public object Get(GetGeoserverWorkspaceStylesRequestTep request) { var context = TepWebContext.GetWebContext(PagePrivileges.EverybodyView); GeoserverStylesResponse result = null; try { context.Open(); context.LogInfo(this, string.Format("/geoserver/workspace/styles GET, identifier='{0}'", request.identifier)); result = GeoserverFactory.GetStylesForWorkspace(request.identifier); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(new HttpResult(result)); }
public object Put(UserUpdateSSORequestTep request) { WebUserTep result; var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly); try { context.Open(); context.LogInfo(this, string.Format("/user/sso PUT Identifier='{0}',T2Username='******'", request.Identifier, request.T2Username)); UserTep user = UserTep.FromIdentifier(context, request.Identifier); user.TerradueCloudUsername = request.T2Username; user.StoreCloudUsername(); result = new WebUserTep(context, user); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }
/// <summary> /// Get the specified request. /// </summary> /// <param name="request">Request.</param> public object Get(RoleGetRequest request) { WebRole result; var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly); try { context.Open(); context.LogInfo(this, string.Format("/role/{{Id}} GET Id='{0}'", request.Id)); Role role = Role.FromId(context, request.Id); result = new WebRole(role, true); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }
public object Get(GetGeoserverGlobalStylesRequestTep request) { var context = TepWebContext.GetWebContext(PagePrivileges.EverybodyView); GeoserverStylesResponse result = null; try { context.Open(); context.LogInfo(this, string.Format("/geoserver/styles GET")); result = GeoserverFactory.GetGlobalStyles(); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(new HttpResult(result)); }
public object Put(UpdateBulkUsersProfileFromRemoteTep request) { IfyWebContext context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly); try { context.Open(); context.LogInfo(this, string.Format("/users/profile PUT Ids='{0}'", string.Join(",", request.Identifiers))); foreach (var identifier in request.Identifiers) { try { var usr = UserTep.FromIdentifier(context, identifier); usr.LoadProfileFromRemote(); }catch (Exception e) { context.LogError(this, e.Message + " - " + e.StackTrace); } } try{ var portalname = string.Format("{0} Portal", context.GetConfigValue("SiteNameShort")); var subject = context.GetConfigValue("EmailBulkActionSubject"); subject = subject.Replace("$(SITENAME)", portalname); var body = context.GetConfigValue("EmailBulkActionBody"); body = body.Replace("$(ADMIN)", context.Username); body = body.Replace("$(ACTION)", "User remote profile load"); body = body.Replace("$(IDENTIFIERS)", string.Join(",", request.Identifiers)); context.SendMail(context.GetConfigValue("SmtpUsername"), context.GetConfigValue("SmtpUsername"), subject, body); } catch (Exception e) { context.LogError(this, e.Message + " - " + e.StackTrace); } context.Close(); } catch (Exception e) { context.LogError(this, e.Message + " - " + e.StackTrace); context.Close(); throw e; } return(true); }
public object Get(GetImages request) { List <string> result = new List <string>(); var context = TepWebContext.GetWebContext(PagePrivileges.EverybodyView); try { context.Open(); var imgpath = context.GetConfigValue("path.img"); // var rootpath = imgpath.Substring(imgpath.LastIndexOf("/root") + 5); // result = System.IO.Directory.GetFiles(imgpath, !string.IsNullOrEmpty(request.q) ? "*" + request.q + "*" : "*").ToList(); // result = result.ConvertAll(f => rootpath + "/" + f.Substring(f.LastIndexOf("/") + 1)); var allresult = System.IO.Directory.GetFiles(imgpath, "*").ToList(); if (!string.IsNullOrEmpty(request.q)) { foreach (var f in allresult) { var filename = f.Substring(f.LastIndexOf("/") + 1); if (filename.ToLower().Contains(request.q.ToLower())) { result.Add(f); } } } else { result = allresult; } var rootpath = context.GetConfigValue("BaseUrl").TrimEnd('/') + "/" + imgpath.Substring(imgpath.LastIndexOf("/root/") + 6);; result = result.ConvertAll(f => rootpath + "/" + f.Substring(f.LastIndexOf("/") + 1)); context.Close(); } catch (Exception e) { context.Close(); throw e; } return(result); }
public object Get(LogsGetRequest request) { var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly); List <string> result = new List <string>(); try { context.Open(); context.LogInfo(this, string.Format("/logs GET")); var logpath = context.GetConfigValue("log-path"); result = System.IO.Directory.GetFiles(logpath, "*.log*").ToList(); result = result.ConvertAll(f => f.Substring(f.LastIndexOf("/") + 1)); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }
public object Get(OneGetConfigRequestTep request) { List <KeyValuePair <string, string> > result = new List <KeyValuePair <string, string> >(); var context = TepWebContext.GetWebContext(PagePrivileges.UserView); try { context.Open(); context.LogInfo(this, string.Format("/one/config GET")); string key = "One-access"; result.Add(new KeyValuePair <string, string>(key, context.GetConfigValue(key))); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }
public object Get(OneGetWPSRequestTep request) { List <WpsProvider> result = new List <WpsProvider>(); var context = TepWebContext.GetWebContext(PagePrivileges.UserView); try { context.Open(); context.LogInfo(this, string.Format("/one/wps GET")); CloudWpsFactory wpsFinder = new CloudWpsFactory(context); result = wpsFinder.GetWPSFromVMs(); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }
/// <summary> /// Put the specified request. /// </summary> /// <param name="request">Request.</param> public object Put(RoleUpdateRequest request) { var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly); WebRole result; try { context.Open(); context.LogInfo(this, string.Format("/role PUT Id='{0}'", request.Id)); Role role = Role.FromId(context, request.Id); role = request.ToEntity(context, role); role.Store(); context.LogDebug(this, string.Format("Role {0} updated by user {1}", role.Identifier, User.FromId(context, context.UserId).Username)); result = new WebRole(role, true); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }
public object Delete(DeleteRatesFromProviderRequestTep request) { var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly); try { context.Open(); context.LogInfo(this, string.Format("/cr/wps/{{providerIdentifier}}/rates/{{id}} DELETE providerIdentifier='{0}', Id='{1}'", request.ProviderIdentifier, request.Id)); var service = WpsProvider.FromIdentifier(context, request.ProviderIdentifier); Rates rate = Rates.FromId(context, request.Id); context.LogInfo(this, string.Format("Deleting rates {0} of service {1}", rate.Identifier, service.Identifier)); rate.Delete(); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(new WebResponseBool(true)); }
public object Put(UserUpdateAdminRequestTep request) { var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly); WebUserTep result; try { context.Open(); context.LogInfo(this, string.Format("/user/admin PUT Id='{0}'", request.Id)); UserTep user = (request.Id == 0 ? null : UserTep.FromId(context, request.Id)); user.Level = request.Level; user.Store(); context.LogDebug(this, string.Format("Level of user '{0}' has been updated to Level {1}", user.Username, request.Level)); result = new WebUserTep(context, user); 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 Delete(RemoveUserFromGroup request) { var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly); WebGroup result; try{ context.Open(); context.LogInfo(this, string.Format("/group/{{grpId}}/user/{{usrId}} DELETE grpId='{0}',usrId='{1}'", request.GrpId, request.UsrId)); context.RemoveUserFromGroup(request.UsrId, request.GrpId); User usr = User.FromId(context, request.UsrId); Group grp = Group.FromId(context, request.GrpId); result = new WebGroup(grp); context.LogDebug(this, string.Format("User {0} has been removed from group {1}", usr.Username, grp.Name)); context.Close(); }catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }
/// <summary> /// Get the specified request. /// </summary> /// <param name="request">Request.</param> public object Get(GetTermsConditionsForCurrentUserRequestTep request) { WebResponseBool response; var context = TepWebContext.GetWebContext(PagePrivileges.UserView); try { context.Open(); context.LogInfo(this, string.Format("/termsconditions/user/current GET")); var check = TermsConditionsHelper.CheckTermsConditionsForCurrentUser(context, request.identifier); response = new WebResponseBool(check); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(response); }
public object Get(OneGetImageRequestTep request) { string result = null; var context = TepWebContext.GetWebContext(PagePrivileges.UserView); try { context.Open(); context.LogInfo(this, string.Format("/one/{{providerId}}/img/{{imageId}} GET providerId='{0}',imageId='{1}'", request.ProviderId, request.ImageId)); int provId = (request.ProviderId != 0 ? request.ProviderId : context.GetConfigIntegerValue("One-default-provider")); OneCloudProvider oneCloud = (OneCloudProvider)CloudProvider.FromId(context, provId); IMAGE oneuser = oneCloud.XmlRpc.ImageGetInfo(request.ImageId); result = oneuser.NAME; context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }
/// <summary> /// Get the specified request. /// </summary> /// <param name="request">Request.</param> public object Get(GetDataPackageTep request) { //Get all requests from database var context = TepWebContext.GetWebContext(PagePrivileges.UserView); WebDataPackageTep result; try{ context.Open(); context.LogInfo(this, string.Format("/data/package/{{Identifier}} GET Id='{0}", request.Identifier)); DataPackage tmp = DataPackage.FromIdentifier(context, request.Identifier); result = new WebDataPackageTep(tmp); context.Close(); }catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }
public object Delete(SerieDeleteRequestTep request) { List <WebGroup> result = new List <WebGroup>(); var context = TepWebContext.GetWebContext(PagePrivileges.UserView); try { context.Open(); context.LogInfo(this, string.Format("/data/collection/{{collId}} DELETE collId='{0}'", request.Identifier)); Series serie = Series.FromIdentifier(context, request.Identifier); serie.Delete(); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(new WebResponseBool(true)); }
/// <summary> /// Delete the specified request. /// </summary> /// <param name="request">Request.</param> public object Delete(RemoveItemFromDataPackage request) { var context = TepWebContext.GetWebContext(PagePrivileges.UserView); WebDataPackageTep result; try{ context.Open(); context.LogInfo(this, string.Format("/data/package/{{DpId}}/item/{{Id}} POST DpId='{0}', Id='{1}'", request.DpId, request.Id)); RemoteResource tmp = RemoteResource.FromId(context, request.Id); tmp.Delete(); DataPackage dp = DataPackage.FromId(context, request.DpId); result = new WebDataPackageTep(dp); context.Close(); }catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }
/// <summary> /// Put the specified request. /// </summary> /// <param name="request">Request.</param> public object Put(DomainUpdateRequest request) { var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly); WebDomain result; try { context.Open(); context.LogInfo(this, string.Format("/domain PUT Id='{0}'", request.Id)); Domain domain = (request.Id == 0 ? null : Domain.FromId(context, request.Id)); domain = request.ToEntity(context, domain); domain.Store(); context.LogDebug(this, string.Format("Domain {0} updated by user {1}", domain.Identifier, User.FromId(context, context.UserId).Username)); result = new WebDomain(domain); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }
public object Post(UserAddTransactionRequestTep request) { var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly); WebUserTep result; try { context.Open(); context.LogInfo(this, string.Format("/transaction/user POST Identifier='{0}', Balance='{1}'", request.Identifier, request.Balance)); UserTep user = UserTep.FromIdentifier(context, request.Identifier); user.AddAccountingTransaction(request.Balance, (TransactionKind)request.Kind); result = new WebUserTep(context, user); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }
public object Get(DataPackagesDescriptionRequest request) { var context = TepWebContext.GetWebContext(PagePrivileges.EverybodyView); try { context.Open(); context.LogInfo(this, string.Format("/data/package/description GET")); EntityList <Terradue.Tep.DataPackage> tmp_datapackages = new EntityList <DataPackage> (context); OpenSearchDescription osd = tmp_datapackages.GetOpenSearchDescription(); context.Close(); return(new HttpResult(osd, "application/opensearchdescription+xml")); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } }
/// <summary> /// Update the specified group. /// </summary> /// <param name="request">Request.</param> /// <returns>the group</returns> public object Put(UpdateGroup request) { var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly); WebGroup result; try { context.Open(); context.LogInfo(this, string.Format("/group PUT Id='{0}'", request.Id)); Group grp = (request.Id == 0 ? null : Group.FromId(context, request.Id)); grp = request.ToEntity(context, grp); grp.Store(); context.LogDebug(this, string.Format("Group {0} updated by user {1}", grp.Name, User.FromId(context, context.UserId).Username)); result = new WebGroup(grp); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }
public object Get(GetUsersFromGroup request) { var context = TepWebContext.GetWebContext(PagePrivileges.UserView); List <WebUser> result = new List <WebUser>();; try{ context.Open(); context.LogInfo(this, string.Format("/group/{{grpId}}/user GET grpId='{0}'", request.GrpId)); Group grp = Group.FromId(context, request.GrpId); foreach (User u in grp.GetUsers()) { result.Add(new WebUser(u)); } context.Close(); }catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }
public object Get(GetConfig request) { List <KeyValuePair <string, string> > result = new List <KeyValuePair <string, string> >(); var context = TepWebContext.GetWebContext(PagePrivileges.EverybodyView); try { context.Open(); result.Add(new KeyValuePair <string, string>("geobrowserDateMin", context.GetConfigValue("geobrowser-date-min"))); result.Add(new KeyValuePair <string, string>("geobrowserDateMax", context.GetConfigValue("geobrowser-date-max"))); result.Add(new KeyValuePair <string, string>("Github-client-id", context.GetConfigValue("Github-client-id"))); result.Add(new KeyValuePair <string, string>("enableAccounting", context.GetConfigValue("accounting-enabled"))); context.Close(); } catch (Exception e) { context.Close(); throw e; } return(result); }
/// <summary> /// Post the specified request. /// </summary> /// <param name="request">Request.</param> public object Post(CommunityAddUserRequestTep request) { var context = TepWebContext.GetWebContext(PagePrivileges.UserView); try { context.Open(); if (string.IsNullOrEmpty(request.Identifier)) { throw new Exception("Invalid request - missing community identifier"); } User user = string.IsNullOrEmpty(request.Username) ? User.FromId(context, context.UserId) : User.FromUsername(context, request.Username); //we use administrator access level to be able to load the community context.AccessLevel = EntityAccessLevel.Administrator; ThematicCommunity domain = ThematicCommunity.FromIdentifier(context, request.Identifier); Role role = Role.FromIdentifier(context, string.IsNullOrEmpty(request.Role) ? domain.DefaultRoleName : request.Role); context.LogInfo(this, string.Format("/community/user POST Identifier='{0}', Username='******', Role='{2}'", request.Identifier, user.Username, role.Identifier)); if (string.IsNullOrEmpty(request.Username)) { //case user auto Join domain.TryJoinCurrentUser(request.Objectives); } else { //case owner add user with role domain.SetUserRole(user, role); } context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(new WebResponseBool(true)); }
public object Post(KMLPostRequestTep request) { var context = TepWebContext.GetWebContext(PagePrivileges.EverybodyView); context.Open(); context.LogInfo(this, string.Format("/geometry/kml GET")); if (request.points == 0) { var segments = base.Request.PathInfo.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); request.points = System.Int32.Parse(segments[segments.Count() - 1]); } var points = request.points > 0 ? request.points : 3000; string wkt = null; using (var stream = new MemoryStream()) { if (this.RequestContext.Files.Length > 0) { this.RequestContext.Files[0].InputStream.CopyTo(stream); } else { request.RequestStream.CopyTo(stream); } wkt = ExtractWKTFromKML(stream, points); } context.Close(); if (!string.IsNullOrEmpty(wkt)) { return(new WebResponseString(wkt)); } else { throw new Exception("Unable to get WKT"); } }
public object Get(TransactionsSearchRequestTep request) { var context = TepWebContext.GetWebContext(PagePrivileges.UserView); IOpenSearchResultCollection result; try { context.Open(); context.LogInfo(this, string.Format("/transaction/search GET")); // Load the complete request var httpRequest = HttpContext.Current.Request; EntityList <Transaction> transactions = new EntityList <Transaction>(context); if (context.AccessLevel != EntityAccessLevel.Administrator || httpRequest.QueryString["author"] == null) { //Only admin can see others transactions transactions.SetFilter("OwnerId", context.UserId + ""); } else { var user = UserTep.FromIdentifier(context, httpRequest.QueryString["author"]); transactions.SetFilter("OwnerId", user.Id + ""); } transactions.AddSort("LogTime", SortDirection.Descending); var ose = MasterCatalogue.OpenSearchEngine; Type responseType = OpenSearchFactory.ResolveTypeFromRequest(httpRequest.QueryString, httpRequest.Headers, ose); result = ose.Query(transactions, httpRequest.QueryString, responseType); OpenSearchFactory.ReplaceOpenSearchDescriptionLinks(transactions, result); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(new HttpResult(result.SerializeToString(), result.ContentType)); }
public object Get(LogGetRequest request) { var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly); var text = new System.Text.StringBuilder(); try { context.Open(); context.LogInfo(this, string.Format("/log GET filename='{0}'", request.filename)); var logpath = context.GetConfigValue("log-path"); var filepath = string.Format("{1}/{0}", request.filename, logpath); List <string> lines = new List <string>(); using (var csv = new FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) using (var sr = new StreamReader(csv)){ while (!sr.EndOfStream) { lines.Add(sr.ReadLine()); } } List <string> lines2 = new List <string> (); for (int i = 0; i < lines.Count; i++) { var newline = lines[i]; while (i < lines.Count - 1 && !IsNewLog(lines[i + 1])) { newline += lines[++i]; } lines2.Add(newline); } context.Close(); return(lines2.ToArray()); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } }
/// <summary> /// Put the specified request. /// </summary> /// <param name="request">Request.</param> public object Put(DataPackageUpdateGroupsRequestTep request) { var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly); try { context.Open(); context.LogInfo(this, string.Format("/data/package/{{DpId}}/group PUT DpId='{0}', Id='{1}'", request.DpId, request.ToArray() != null ? string.Join(",", request.ToArray()) : "null")); DataPackage dp = DataPackage.FromIdentifier(context, request.DpId); string sql = String.Format("DELETE FROM resourceset_perm WHERE id_resourceset={0} AND id_grp IS NOT NULL;", dp.Id); context.Execute(sql); dp.GrantPermissionsToGroups(request.ToArray()); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(new WebResponseBool(true)); }
/// <summary> /// Delete the specified request. /// </summary> /// <param name="request">Request.</param> public object Delete(DataPackageDeleteRequestTep request) { var context = TepWebContext.GetWebContext(PagePrivileges.UserView); try{ context.Open(); context.LogInfo(this, string.Format("/data/package/{{Identifier}} DELETE Identifier='{0}'", request.Identifier)); DataPackage tmp = DataPackage.FromIdentifier(context, request.Identifier); if (tmp.OwnerId != context.UserId && context.AccessLevel != EntityAccessLevel.Administrator) { throw new UnauthorizedAccessException("You are not authorized to delete this data package."); } tmp.Delete(); context.Close(); }catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(Get(new GetAllDataPackages())); }