/// <summary> /// Get the specified request. /// </summary> /// <param name="request">Request.</param> public object Get(WpsJobGetGroupsRequestTep request) { List <WebGroup> result = new List <WebGroup>(); var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly); try { context.Open(); context.LogInfo(this, string.Format("/job/wps/{{jobId}}/group GET jobId='{0}'", request.JobId)); WpsJob job = WpsJob.FromIdentifier(context, request.JobId); var gids = job.GetAuthorizedGroupIds(); List <int> ids = gids != null?gids.ToList() : new List <int>(); List <Group> groups = new List <Group>(); foreach (int id in ids) { groups.Add(Group.FromId(context, id)); } foreach (Group grp in groups) { result.Add(new WebGroup(grp)); } context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }
/// <summary> /// Post the specified request. /// </summary> /// <param name="request">Request.</param> public object Post(WpsJobAddGroupRequestTep request) { var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly); try { context.Open(); context.LogInfo(this, string.Format("/job/wps/{{jobId}}/group POST jobId='{0}',Id='{1}'", request.JobId, request.Id)); WpsJob wps = WpsJob.FromIdentifier(context, request.JobId); var gids = wps.GetAuthorizedGroupIds(); List <int> ids = gids != null?gids.ToList() : new List <int>(); List <Group> groups = new List <Group>(); foreach (int id in ids) { groups.Add(Group.FromId(context, id)); } foreach (Group grp in groups) { if (grp.Id == request.Id) { return(new WebResponseBool(false)); } } wps.GrantPermissionsToGroups(new int[] { request.Id }); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(new WebResponseBool(true)); }
public object Post(WpsJobSendContactEmailRequestTep request) { var context = TepWebContext.GetWebContext(PagePrivileges.UserView); try { context.Open(); context.LogInfo(this, string.Format("/job/wps/{{identifier}}/contact POST identifier='{0}', subject='{1}', body='{2}'", request.JobId, request.Subject, request.Body)); WpsJob job = WpsJob.FromIdentifier(context, request.JobId); //user must be the owner of the job if (context.UserId != job.OwnerId) { throw new Exception("Sorry, you must be the owner of the job to contact the service provider for job analysis."); } if (job.Provider == null) { throw new Exception("Unable to find WPS Provider contact"); } var contact = job.ExtractProviderContact(job.Provider.Contact); //send email from job's owner to mailto context.SendMail(job.Owner.Email, contact, request.Subject, request.Body); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(new WebResponseBool(true)); }
public object Get(ProxyWpsJobDescriptionRequestTep request) { var context = TepWebContext.GetWebContext(PagePrivileges.EverybodyView); context.Open(); context.LogInfo(this, string.Format("/proxy/wps/{{jobid}}/description GET jobid='{0}'", request.jobid)); WpsJob wpsjob = WpsJob.FromIdentifier(context, request.jobid); context.LogDebug(this, string.Format("Wps Proxy description for wpsjob {0}", wpsjob.Identifier)); OpenSearchDescription osd = GetWpsOpenSearchDescription(context, request.jobid, wpsjob.Name); context.Close(); return(new HttpResult(osd, "application/opensearchdescription+xml")); }
public object Put(WpsJobUpdateRequestTep request) { var context = TepWebContext.GetWebContext(PagePrivileges.UserView); context.Open(); context.LogInfo(this, string.Format("/job/wps PUT Id='{0}'", request.Id)); WpsJob job = WpsJob.FromIdentifier(context, request.Identifier); try{ job.Name = request.Name; job.Store(); context.LogDebug(this, string.Format("WpsJob '{0}' updated", job.Name)); }catch (Exception e) { throw e; } EntityList <WpsJob> wpsjobs = new EntityList <WpsJob>(context); wpsjobs.ItemVisibility = EntityItemVisibility.OwnedOnly; wpsjobs.Load(); OpenSearchEngine ose = MasterCatalogue.OpenSearchEngine; string format; if (Request.QueryString["format"] == null) { format = "atom"; } else { format = Request.QueryString["format"]; } NameValueCollection nvc = new NameValueCollection(); nvc.Add("id", job.Identifier); Type responseType = OpenSearchFactory.ResolveTypeFromRequest(HttpContext.Current.Request.QueryString, HttpContext.Current.Request.Headers, ose); IOpenSearchResultCollection osr = ose.Query(wpsjobs, nvc, responseType); OpenSearchFactory.ReplaceOpenSearchDescriptionLinks(wpsjobs, osr); context.Close(); return(new HttpResult(osr.SerializeToString(), osr.ContentType)); }
public object Put(WpsJobCopyRequestTep request) { var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly); try { context.Open(); context.LogInfo(this, string.Format("/job/wps/copy PUT Id='{0}'", request.Id)); WpsJob job = WpsJob.FromIdentifier(context, request.Identifier); WpsJob newjob = WpsJob.Copy(job, context); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(new WebResponseBool(true)); }
public object Put(WpsJobUpdateNbResultsRequestTep request) { var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly); int nbresults = 0; try { context.Open(); context.LogInfo(this, string.Format("/job/wps/{{identifier}}/nbresults PUT identifier='{0}'", request.JobId)); WpsJob job = WpsJob.FromIdentifier(context, request.JobId); job.UpdateResultCount(); nbresults = job.NbResults; context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(nbresults); }
//[Test] public void RefreshWpsjobResultNb() { var usr4 = User.FromUsername(context, "testusr4"); context.StartImpersonation(usr4.Id); try{ var job = WpsJob.FromIdentifier(context, "private-job-usr4"); job.Status = WpsJobStatus.STAGED; job.StatusLocation = "https://recast.terradue.com/t2api/describe/fpacini/_results/workflows/geohazards_tep_dcs_rss_band_combination_band_combination_1_30_0/run/16641c36-f94f-11e8-bd04-0242ac110019/0003839-180627100334574-oozie-oozi-W"; job.Store(); Assert.AreEqual(job.NbResults, -1); Actions.RefreshWpsjobResultNb(context); job = WpsJob.FromIdentifier(context, "private-job-usr4"); Assert.AreEqual(job.NbResults, 4); } catch (Exception e) { Assert.Fail(e.Message); } finally { context.EndImpersonation(); } }
/// <summary> /// Put the specified request. /// </summary> /// <param name="request">Request.</param> public object Put(WpsJobUpdateGroupsRequestTep request) { var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly); try { context.Open(); context.LogInfo(this, string.Format("/job/wps/{{jobId}}/group PUT jobId='{0}',Id='{1}'", request.JobId, request.ToArray() != null ? string.Join(",", request.ToArray()) : "null")); WpsJob wps = WpsJob.FromIdentifier(context, request.JobId); string sql = String.Format("DELETE FROM wpsjob_perm WHERE id_wpsjob={0} AND id_grp IS NOT NULL;", wps.Id); context.Execute(sql); wps.GrantPermissionsToGroups(request.ToArray()); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(new WebResponseBool(true)); }
public void ShareWpsJobToUser() { context.AccessLevel = EntityAccessLevel.Administrator; var wpsjob = WpsJob.FromIdentifier(context, "restricted-job-usr1-2"); var usr1 = User.FromUsername(context, "testusr1"); context.AccessLevel = EntityAccessLevel.Privilege; context.StartImpersonation(usr1.Id); try { Assert.True(wpsjob.IsSharedToUser()); EntityList <WpsJob> wpsjobs = new EntityList <WpsJob>(context); var parameters = new NameValueCollection(); parameters.Set("q", "restricted-job-usr1-2"); IOpenSearchResultCollection osr = ose.Query(wpsjobs, parameters); Assert.AreEqual(1, osr.TotalResults); bool hasSharedLink = false; foreach (var item in osr.Items) { if (item.Identifier == "restricted-job-usr1-2") { foreach (var link in item.Links) { if (link.RelationshipType == "results") { hasSharedLink = true; } } } } Assert.True(hasSharedLink); } catch (Exception e) { Assert.Fail(e.Message); } finally { context.EndImpersonation(); } }
public object Delete(WpsJobDeleteRequestTep request) { var context = TepWebContext.GetWebContext(PagePrivileges.UserView); bool result = false; try { context.Open(); context.LogInfo(this, string.Format("/job/wps/{{Id}} DELETE Id='{0}'", request.id)); WpsJob job = null; job = WpsJob.FromIdentifier(context, request.id); EventFactory.LogWpsJob(context, job, "Job deleted", "portal_job_delete"); job.Delete(); result = true; context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(new WebResponseBool(result)); }
public void SearchCommunitiesForWpsJob() { context.AccessLevel = EntityAccessLevel.Administrator; ThematicCommunity community = ThematicCommunity.FromIdentifier(context, "community-public-1"); var wpsjob = WpsJob.FromIdentifier(context, "private-job-usr1"); context.AccessLevel = EntityAccessLevel.Privilege; var usr1 = User.FromUsername(context, "testusr1"); context.StartImpersonation(usr1.Id); try { community.TryJoinCurrentUser(); //share as owner and member of community community.ShareEntity(wpsjob); var communities = new EntityList <ThematicCommunity>(context); var parameters = new NameValueCollection(); parameters.Set("correlatedTo", string.Format("{0}/job/wps/search?uid={1}", context.BaseUrl, "private-job-usr1")); IOpenSearchResultCollection osr = ose.Query(communities, parameters); Assert.AreEqual(1, osr.TotalResults); //unshare the job wpsjob.RevokePermissionsFromAll(true, false); wpsjob.DomainId = wpsjob.Owner.DomainId; wpsjob.Store(); Assert.False(wpsjob.IsSharedToCommunity()); } catch (Exception e) { Assert.Fail(e.Message); } finally { context.EndImpersonation(); } }
public object Put(WpsJobUpdateArchiveStatusRequestTep request) { var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly); WebWpsJobTep result; try { context.Open(); context.LogInfo(this, string.Format("/job/wps/{{identifier}}/archive PUT identifier='{0}', status={1}", request.JobId, request.ArchiveStatus)); WpsJob job = WpsJob.FromIdentifier(context, request.JobId); job.ArchiveStatus = (WpsJobArchiveStatus)request.ArchiveStatus; job.Store(); result = new WebWpsJobTep(job); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }
/// <summary> /// Delete the specified request. /// </summary> /// <param name="request">Request.</param> public object Delete(WpsJobDeleteGroupRequestTep request) { List <WebGroup> result = new List <WebGroup>(); var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly); try { context.Open(); context.LogInfo(this, string.Format("/job/wps/{{jobId}}/group/{{Id}} DELETE jobId='{0}',Id='{1}'", request.JobId, request.Id)); WpsJob job = WpsJob.FromIdentifier(context, request.JobId); //TODO: replace once http://project.terradue.com/issues/13954 is resolved string sql = String.Format("DELETE FROM wpjob_perm WHERE id_wpsjob={0} AND id_grp={1};", request.JobId, job.Id); context.Execute(sql); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(new WebResponseBool(true)); }
public object Get(ProxyWpsJobSearchRequestTep request) { var context = TepWebContext.GetWebContext(PagePrivileges.EverybodyView); context.Open(); context.LogInfo(this, string.Format("/proxy/wps/{{jobid}}/search GET jobid='{0}'", request.jobid)); WpsJob wpsjob = WpsJob.FromIdentifier(context, request.jobid); if (string.IsNullOrEmpty(wpsjob.StatusLocation)) { throw new Exception("Invalid Status Location"); } context.LogDebug(this, string.Format("Wps Proxy search for wpsjob {0}", wpsjob.Identifier)); HttpWebRequest executeHttpRequest; if (wpsjob.Provider != null) { executeHttpRequest = wpsjob.Provider.CreateWebRequest(wpsjob.StatusLocation); } else { NetworkCredential credentials = null; var uri = new UriBuilder(wpsjob.StatusLocation); if (!string.IsNullOrEmpty(uri.UserName) && !string.IsNullOrEmpty(uri.Password)) { credentials = new NetworkCredential(uri.UserName, uri.Password); } executeHttpRequest = WpsProvider.CreateWebRequest(wpsjob.StatusLocation, credentials, context.Username); } if (wpsjob.StatusLocation.Contains("gpod.eo.esa.int")) { executeHttpRequest.Headers.Add("X-UserID", context.GetConfigValue("GpodWpsUser")); } OpenGis.Wps.ExecuteResponse execResponse = null; try { context.LogDebug(this, string.Format("Wps proxy - exec response requested - {0}", executeHttpRequest.Address.AbsoluteUri)); using (var response = executeHttpRequest.GetResponse()) using (var stream = response.GetResponseStream()) execResponse = (OpenGis.Wps.ExecuteResponse) new System.Xml.Serialization.XmlSerializer(typeof(OpenGis.Wps.ExecuteResponse)).Deserialize(stream); context.LogDebug(this, string.Format("Wps proxy - exec response OK")); } catch (Exception e) { context.LogError(this, e.Message, e); } if (execResponse == null) { throw new Exception("Unable to get execute response from proxied job"); } execResponse.statusLocation = context.BaseUrl + "/wps/RetrieveResultServlet?id=" + wpsjob.Identifier; context.LogDebug(this, string.Format("Proxy WPS - uri: " + execResponse.statusLocation)); AtomFeed feed = new AtomFeed(); if (execResponse.ProcessOutputs != null) { foreach (OutputDataType output in execResponse.ProcessOutputs) { if (output.Identifier != null && output.Identifier.Value != null && output.Identifier.Value.Equals("result_metadata")) { context.LogDebug(this, string.Format("Wps proxy - metadata")); if (output.Item is OutputReferenceType) { var reference = output.Item as OutputReferenceType; HttpWebRequest atomRequest; if (wpsjob.Provider != null) { atomRequest = wpsjob.Provider.CreateWebRequest(reference.href); } else { NetworkCredential credentials = null; var uri = new UriBuilder(reference.href); if (!string.IsNullOrEmpty(uri.UserName) && !string.IsNullOrEmpty(uri.Password)) { credentials = new NetworkCredential(uri.UserName, uri.Password); } atomRequest = WpsProvider.CreateWebRequest(reference.href, credentials, context.Username); } feed = CreateFeedForMetadata(atomRequest); } else if (output.Item is DataType) { var item = ((DataType)(output.Item)).Item as ComplexDataType; var reference = item.Reference as OutputReferenceType; HttpWebRequest atomRequest; if (wpsjob.Provider != null) { atomRequest = wpsjob.Provider.CreateWebRequest(reference.href); } else { NetworkCredential credentials = null; var uri = new UriBuilder(reference.href); if (!string.IsNullOrEmpty(uri.UserName) && !string.IsNullOrEmpty(uri.Password)) { credentials = new NetworkCredential(uri.UserName, uri.Password); } atomRequest = WpsProvider.CreateWebRequest(reference.href, credentials, context.Username); } feed = CreateFeedForMetadata(atomRequest); } } else { if (output.Item is DataType && ((DataType)(output.Item)).Item != null) { var item = ((DataType)(output.Item)).Item as ComplexDataType; if (item.Any != null && item.Any [0].LocalName != null) { if (item.Any [0].LocalName.Equals("RDF")) { context.LogDebug(this, string.Format("Wps proxy - RDF")); feed = CreateFeedForRDF(item.Any [0], request.jobid, context.BaseUrl); } else if (item.Any [0].LocalName.Equals("metalink")) { context.LogDebug(this, string.Format("Wps proxy - metalink")); feed = CreateFeedForMetalink(item.Any [0], request.jobid, context.BaseUrl, context); } } } } } } /* Proxy id + add self */ foreach (var item in feed.Items) { var self = context.BaseUrl + "/proxy/wps/" + wpsjob.Identifier + "/search?uid=" + HttpUtility.UrlEncode(item.Id); var search = context.BaseUrl + "/proxy/wps/" + wpsjob.Identifier + "/description"; item.Id = self; item.Links.Add(Terradue.ServiceModel.Syndication.SyndicationLink.CreateSelfLink(new Uri(self), "application/atom+xml")); item.Links.Add(new Terradue.ServiceModel.Syndication.SyndicationLink(new Uri(search), "search", "OpenSearch Description link", "application/opensearchdescription+xml", 0)); } feed.Id = wpsjob.StatusLocation; var ose = MasterCatalogue.OpenSearchEngine; Type responseType = OpenSearchFactory.ResolveTypeFromRequest(HttpContext.Current.Request.QueryString, HttpContext.Current.Request.Headers, ose); var ext = ose.GetFirstExtensionByTypeAbility(responseType); var osfeed = new AtomFeedOpenSearchable(feed); IOpenSearchResultCollection osr = ose.Query(osfeed, HttpContext.Current.Request.QueryString, responseType); var osrDesc = new Uri(context.BaseUrl + "/proxy/wps/" + wpsjob.Identifier + "/description"); osr.Links.Add(new Terradue.ServiceModel.Syndication.SyndicationLink(osrDesc, "search", "OpenSearch Description link", "application/opensearchdescription+xml", 0)); context.Close(); return(new HttpResult(osr.SerializeToString(), osr.ContentType)); }
public void ShareWpsJobToCommunity() { context.AccessLevel = EntityAccessLevel.Administrator; ThematicCommunity community = ThematicCommunity.FromIdentifier(context, "community-public-1"); var wpsjob = WpsJob.FromIdentifier(context, "private-job-usr1"); var wpsjob2 = WpsJob.FromIdentifier(context, "private-job-usr2"); context.AccessLevel = EntityAccessLevel.Privilege; var usr1 = User.FromUsername(context, "testusr1"); context.StartImpersonation(usr1.Id); try { //share as non owner try { community.ShareEntity(wpsjob2); Assert.Fail("Cannot share as non owner"); } catch (Exception) { } //share as owner and not member of community try { community.ShareEntity(wpsjob2); Assert.Fail("Cannot share as non member"); } catch (Exception) { } community.TryJoinCurrentUser(); //share as owner and member of community community.ShareEntity(wpsjob); Assert.True(wpsjob.IsSharedToCommunity()); EntityList <WpsJob> wpsjobs = new EntityList <WpsJob>(context); var parameters = new NameValueCollection(); parameters.Set("q", "private-job-usr1"); IOpenSearchResultCollection osr = ose.Query(wpsjobs, parameters); Assert.AreEqual(1, osr.TotalResults); bool hasSharedLink = false; foreach (var item in osr.Items) { if (item.Identifier == "private-job-usr1") { foreach (var link in item.Links) { if (link.RelationshipType == "results") { hasSharedLink = true; } } } } Assert.True(hasSharedLink); //unshare the job wpsjob.RevokePermissionsFromAll(true, false); wpsjob.DomainId = wpsjob.Owner.DomainId; wpsjob.Store(); Assert.False(wpsjob.IsSharedToCommunity()); wpsjobs = new EntityList <WpsJob>(context); parameters = new NameValueCollection(); parameters.Set("q", "private-job-usr1"); osr = ose.Query(wpsjobs, parameters); Assert.AreEqual(1, osr.TotalResults); hasSharedLink = false; foreach (var item in osr.Items) { if (item.Identifier == "private-job-usr1") { foreach (var link in item.Links) { if (link.RelationshipType == "results") { hasSharedLink = true; } } } } Assert.False(hasSharedLink); } catch (Exception e) { Assert.Fail(e.Message); } finally { context.EndImpersonation(); } }
public object Post(WpsJobSendSupportEmailRequestTep request) { var context = TepWebContext.GetWebContext(PagePrivileges.UserView); try { context.Open(); context.LogInfo(this, string.Format("/job/wps/{{identifier}}/support POST identifier='{0}', subject='{1}', body='{2}'", request.JobId, request.Subject, request.Body)); WpsJob job = WpsJob.FromIdentifier(context, request.JobId); //user must be the owner of the job if (context.UserId != job.OwnerId) { throw new Exception("Sorry, you must be the owner of the job to contact the support for job analysis."); } var supportModes = context.GetConfigValue("wpsjob-support-mode").Split(','); if (supportModes.Contains("mail")) { //send email from job's owner to mailto context.SendMail(job.Owner.Email ?? context.GetConfigValue("MailSenderAddress"), context.GetConfigValue("MailSenderAddress"), request.Subject, request.Body); } if (supportModes.Contains("jira")) { //create JIRA ticket var components = new List <JiraNameProperty>(); var configComponents = context.GetConfigValue("jira-helpdesk-components"); if (!string.IsNullOrEmpty(configComponents)) { var componentsList = configComponents.Split(','); foreach (var component in componentsList) { components.Add(new JiraNameProperty { name = component }); } } var labels = new List <string>(); var configLabels = context.GetConfigValue("jira-helpdesk-labels"); if (!string.IsNullOrEmpty(configLabels)) { labels = configLabels.Split(',').ToList(); } var owner = job.Owner; if (string.IsNullOrEmpty(owner.TerradueCloudUsername)) { owner.LoadCloudUsername(); } var raiseOnBehalfOf = owner.TerradueCloudUsername; var issue = new JiraServiceDeskIssueRequest { serviceDeskId = context.GetConfigValue("jira-helpdesk-serviceDeskId"), requestTypeId = context.GetConfigValue("jira-helpdesk-requestTypeId"), raiseOnBehalfOf = raiseOnBehalfOf, requestFieldValues = new JiraServiceDeskIssueFields { summary = request.Subject, description = request.Body, components = components, labels = labels } }; if (!string.IsNullOrEmpty(context.GetConfigValue("jira-helpdesk-customfield-ThematicAppLabel"))) { issue.requestFieldValues.thematicAppLabels = new List <string> { request.AppId }; } if (!string.IsNullOrEmpty(context.GetConfigValue("jira-helpdesk-customfield-ProcessingServiceLabel"))) { if (job.Process != null && !string.IsNullOrEmpty(job.Process.Name)) { var process = job.Process.Name.Replace(' ', '-'); issue.requestFieldValues.processingServicesLabels = new List <string> { process }; } } var jira = new JiraClient(context); try { jira.CreateServiceDeskIssue(issue); }catch (Exception) { issue.raiseOnBehalfOf = job.Owner.Email; jira.CreateServiceDeskIssue(issue); } } context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(new WebResponseBool(true)); }
private List <Transaction> GetRemoteTransactions(string username, DateTime timestamp) { List <Transaction> transactions = new List <Transaction>(); var url = context.GetConfigValue("t2-accounting-baseurl"); if (string.IsNullOrEmpty(url)) { return(transactions); } var request = (HttpWebRequest)WebRequest.Create(url); request.Method = "POST"; request.ContentType = "application/json"; request.Proxy = null; request.Timeout = 3000; var estr = GetTransactionJsonToPost(username, timestamp); string json = JsonSerializer.SerializeToString <ElasticTransactionSearchRequest>(estr); try { using (var streamWriter = new StreamWriter(request.GetRequestStream())) { streamWriter.Write(json); streamWriter.Flush(); streamWriter.Close(); using (var httpResponse = (HttpWebResponse)request.GetResponse()) { using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { string result = streamReader.ReadToEnd(); var etResponse = JsonSerializer.DeserializeFromString <ElasticTransactionSearchResponse>(result); var userBuckets = etResponse.aggregations.user.buckets[0].account_ref.buckets; foreach (var bucket in userBuckets) { var identifier = bucket.key; try{ //get job and service var job = WpsJob.FromIdentifier(context, identifier); var entityservice = job.Process.Provider; double balance = 0; foreach (var qBucket in bucket.quantities.quantity.buckets) { //calculate balance if (!string.IsNullOrEmpty(qBucket.key) && qBucket.total != null) { balance += Rates.GetBalanceFromRate(context, entityservice, qBucket.key, qBucket.total.value); } } var transaction = new Transaction(context); transaction.Entity = job; transaction.OwnerId = job.OwnerId; transaction.Identifier = identifier; transaction.LogTime = DateTime.UtcNow; transaction.ProviderId = entityservice.OwnerId; transaction.Balance = balance; transaction.Kind = TransactionKind.Debit; transactions.Add(transaction); } catch (Exception e) { context.LogError(this, e.Message); } } } } } } catch (Exception e) { context.LogError(this, e.Message); } return(transactions); }
public object Get(WpsJobProductSearchRequestTep request) { var context = TepWebContext.GetWebContext(PagePrivileges.EverybodyView); HttpResult result = null; try { context.Open(); context.LogInfo(this, string.Format("/job/wps/{0}/products/search GET", request.JobId)); WpsJob wpsjob = null; try { wpsjob = WpsJob.FromIdentifier(context, request.JobId); } catch (Exception e) { if (request.Key != null) //or if public { context.AccessLevel = EntityAccessLevel.Administrator; wpsjob = WpsJob.FromIdentifier(context, request.JobId); if (request.Key != null && !request.Key.Equals(wpsjob.AccessKey)) { throw new UnauthorizedAccessException(CustomErrorMessages.WRONG_ACCESSKEY); } } else { throw e; } } OpenSearchEngine ose = MasterCatalogue.OpenSearchEngine; HttpRequest httpRequest = HttpContext.Current.Request; Type type = OpenSearchFactory.ResolveTypeFromRequest(httpRequest.QueryString, httpRequest.Headers, ose); var nvc = httpRequest.QueryString; if (CatalogueFactory.IsCatalogUrl(new Uri(wpsjob.StatusLocation))) { var settings = MasterCatalogue.OpenSearchFactorySettings; OpenSearchableFactorySettings specsettings = (OpenSearchableFactorySettings)settings.Clone(); //get credentials from current user if (context.UserId != 0) { var user = UserTep.FromId(context, context.UserId); var apikey = user.GetSessionApiKey(); var t2userid = user.TerradueCloudUsername; if (!string.IsNullOrEmpty(apikey)) { specsettings.Credentials = new System.Net.NetworkCredential(t2userid, apikey); } } GenericOpenSearchable urlToShare = new GenericOpenSearchable(new OpenSearchUrl(wpsjob.StatusLocation), specsettings); var res = ose.Query(urlToShare, nvc, type); result = new HttpResult(res.SerializeToString(), res.ContentType); } else { WpsJobProductOpenSearchable wpsjobProductOs = new WpsJobProductOpenSearchable(wpsjob, context); //var nvc = wpsjobUrl.GetParameters (); var res = ose.Query(wpsjobProductOs, nvc, type); OpenSearchFactory.ReplaceSelfLinks(wpsjobProductOs, httpRequest.QueryString, res, EntrySelfLinkTemplate); OpenSearchFactory.ReplaceOpenSearchDescriptionLinks(wpsjobProductOs, res); result = new HttpResult(res.SerializeToString(), res.ContentType); } context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }
public object Get(WpsJobProductDescriptionRequestTep request) { var context = TepWebContext.GetWebContext(PagePrivileges.EverybodyView); HttpResult result = null; try { context.Open(); context.LogInfo(this, string.Format("/job/wps/{0}/products/description GET", request.JobId)); WpsJob wpsjob = WpsJob.FromIdentifier(context, request.JobId); OpenSearchEngine ose = MasterCatalogue.OpenSearchEngine; HttpRequest httpRequest = HttpContext.Current.Request; OpenSearchDescription osd; if (CatalogueFactory.IsCatalogUrl(new Uri(wpsjob.StatusLocation))) { var settings = MasterCatalogue.OpenSearchFactorySettings; OpenSearchableFactorySettings specsettings = (OpenSearchableFactorySettings)settings.Clone(); //get credentials from current user if (context.UserId != 0) { var user = UserTep.FromId(context, context.UserId); var apikey = user.GetSessionApiKey(); var t2userid = user.TerradueCloudUsername; if (!string.IsNullOrEmpty(apikey)) { specsettings.Credentials = new System.Net.NetworkCredential(t2userid, apikey); } } GenericOpenSearchable urlToShare = new GenericOpenSearchable(new OpenSearchUrl(wpsjob.StatusLocation), specsettings); osd = urlToShare.GetOpenSearchDescription(); var oldUri = new UriBuilder(osd.DefaultUrl.Template); var newUri = new UriBuilder(context.BaseUrl + "/job/wps/" + wpsjob.Identifier + "/products/search"); newUri.Query = oldUri.Query.TrimStart("?".ToCharArray()); osd.DefaultUrl.Template = HttpUtility.UrlDecode(newUri.Uri.AbsoluteUri); foreach (var url in osd.Url) { oldUri = new UriBuilder(url.Template); newUri = new UriBuilder(context.BaseUrl + "/job/wps/" + wpsjob.Identifier + "/products/search"); newUri.Query = oldUri.Query.TrimStart("?".ToCharArray()); url.Template = HttpUtility.UrlDecode(newUri.Uri.AbsoluteUri); } } else { WpsJobProductOpenSearchable wpsjobProductOs = new WpsJobProductOpenSearchable(wpsjob, context); osd = wpsjobProductOs.GetProxyOpenSearchDescription(); } result = new HttpResult(osd, "application/opensearchdescription+xml"); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }