Skip to content

Commit

Permalink
Merge pull request #1916 from scireum/feature/sbi/OX-10601
Browse files Browse the repository at this point in the history
Replaces calls to deprecated methods
  • Loading branch information
sabieber authored Jan 5, 2024
2 parents 17871aa + 7363ef4 commit 82d839c
Show file tree
Hide file tree
Showing 19 changed files with 226 additions and 238 deletions.
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
<packaging>jar</packaging>

<name>SIRIUS biz</name>
<description>Provides a framework for building web based business applications</description>
<url>http://www.sirius-lib.net</url>
<description>Provides a framework for building web-based business applications</description>
<url>https://www.sirius-lib.net</url>

<properties>
<sirius.kernel>dev-42.0.0</sirius.kernel>
<sirius.web>dev-75.0.0</sirius.web>
<sirius.kernel>dev-42.1.0</sirius.kernel>
<sirius.web>dev-75.1.0</sirius.web>
<sirius.db>dev-57.0.0</sirius.db>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import sirius.db.mixing.Mapping;
import sirius.db.mixing.annotations.BeforeSave;
import sirius.db.mixing.annotations.NullAllowed;
import sirius.kernel.async.CallContext;
import sirius.kernel.commons.Strings;
import sirius.web.controller.ControllerDispatcher;
import sirius.web.http.WebContext;
Expand Down Expand Up @@ -95,7 +94,7 @@ public class PageImpressionEvent extends Event<PageImpressionEvent> {
@BeforeSave
protected void fillAndCheck() {
if (Strings.isEmpty(uri) || Strings.isEmpty(aggregationUri)) {
WebContext webContext = CallContext.getCurrent().get(WebContext.class);
WebContext webContext = WebContext.getCurrent();
if (webContext.isValid()) {
if (Strings.isEmpty(uri)) {
uri = webContext.getRequestedURI();
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/sirius/biz/analytics/events/UserData.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import sirius.db.mixing.Mapping;
import sirius.db.mixing.annotations.BeforeSave;
import sirius.db.mixing.annotations.NullAllowed;
import sirius.kernel.async.CallContext;
import sirius.kernel.commons.Strings;
import sirius.web.security.ScopeInfo;
import sirius.web.security.UserContext;
Expand Down Expand Up @@ -45,13 +44,13 @@ public class UserData extends Composite {

@BeforeSave
protected void fill() {
UserContext ctx = CallContext.getCurrent().get(UserContext.class);
if (ctx.getScope() != ScopeInfo.DEFAULT_SCOPE && Strings.isEmpty(scopeId)) {
scopeId = ctx.getScope().getScopeId();
UserContext userContext = UserContext.get();
if (userContext.getScope() != ScopeInfo.DEFAULT_SCOPE && Strings.isEmpty(scopeId)) {
scopeId = userContext.getScope().getScopeId();
}
if (ctx.isUserPresent() && ctx.getUser().isLoggedIn() && Strings.isEmpty(userId)) {
userId = ctx.getUser().getUserId();
tenantId = ctx.getUser().getTenantId();
if (userContext.isUserPresent() && userContext.getUser().isLoggedIn() && Strings.isEmpty(userId)) {
userId = userContext.getUser().getUserId();
tenantId = userContext.getUser().getTenantId();
}
}

Expand Down
13 changes: 6 additions & 7 deletions src/main/java/sirius/biz/analytics/events/WebData.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import sirius.db.mixing.annotations.BeforeSave;
import sirius.db.mixing.annotations.Length;
import sirius.db.mixing.annotations.NullAllowed;
import sirius.kernel.async.CallContext;
import sirius.kernel.commons.Strings;
import sirius.web.http.UserAgent;
import sirius.web.http.WebContext;
Expand Down Expand Up @@ -84,16 +83,16 @@ public class WebData extends Composite {

@BeforeSave
protected void fill() {
WebContext ctx = CallContext.getCurrent().get(WebContext.class);
if (ctx.isValid()) {
WebContext webContext = WebContext.getCurrent();
if (webContext.isValid()) {
if (Strings.isEmpty(url)) {
url = ctx.getRequestedURL();
url = webContext.getRequestedURL();
}
if (Strings.isEmpty(userAgent)) {
persistUserAgent(ctx.getUserAgent());
persistUserAgent(webContext.getUserAgent());
}
if (ctx.getTTFBMillis() > 0 && responseTime == null) {
responseTime = ctx.getTTFBMillis();
if (webContext.getTTFBMillis() > 0 && responseTime == null) {
responseTime = webContext.getTTFBMillis();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private void emitCurrentValue(Report report, String type, String realm, String s
}

private void reportForIP(Report report) {
WebContext webContext = CallContext.getCurrent().get(WebContext.class);
WebContext webContext = WebContext.getCurrent();
if (webContext.isValid()) {
String ip = webContext.getRemoteIP().getHostAddress();
for (String realm : isenguard.getRealmsByType(Isenguard.REALM_TYPE_IP)) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/sirius/biz/isenguard/RateLimitingInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static RateLimitingInfo fromWebContext(WebContext ctx, @Nullable String t
public static RateLimitingInfo fromCurrentContext() {
UserInfo currentUser = UserContext.getCurrentUser();
String tenantId = currentUser.isLoggedIn() ? currentUser.getTenantId() : null;
WebContext webContext = CallContext.getCurrent().get(WebContext.class);
WebContext webContext = WebContext.getCurrent();
if (webContext.isValid()) {
return new RateLimitingInfo(webContext.getRemoteIP().getHostAddress(),
tenantId,
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/sirius/biz/process/ErrorContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class ErrorContext implements SubContext {
* @return the current error context
*/
public static ErrorContext get() {
return CallContext.getCurrent().get(ErrorContext.class);
return CallContext.getCurrent().getOrCreateSubContext(ErrorContext.class);
}

/**
Expand Down
45 changes: 22 additions & 23 deletions src/main/java/sirius/biz/protocol/AuditLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import sirius.db.es.Elastic;
import sirius.kernel.Sirius;
import sirius.kernel.async.CallContext;
import sirius.kernel.di.Initializable;
import sirius.kernel.di.std.Part;
import sirius.kernel.di.std.Register;
Expand Down Expand Up @@ -60,7 +59,7 @@ protected AuditLogBuilder(String message, boolean negative) {
}

private String getCurrentIP() {
WebContext webContext = CallContext.getCurrent().get(WebContext.class);
WebContext webContext = WebContext.getCurrent();
if (webContext.isValid()) {
return webContext.getRemoteIP().getHostAddress();
}
Expand All @@ -75,21 +74,21 @@ private String getCurrentIP() {
*/
@CheckReturnValue
public AuditLogBuilder forCurrentUser() {
UserInfo user = UserContext.getCurrentUser();
return forUser(user.getUserId(), user.getProtocolUsername()).forTenant(user.getTenantId(),
user.getTenantName());
UserInfo userInfo = UserContext.getCurrentUser();
return forUser(userInfo.getUserId(), userInfo.getProtocolUsername()).forTenant(userInfo.getTenantId(),
userInfo.getTenantName());
}

/**
* Creates the entry for the given user.
*
* @param id the ID of the user
* @param name the name of the user
* @param userId the ID of the user
* @param name the name of the user
* @return the builder for fluent method calls
*/
@CheckReturnValue
public AuditLogBuilder forUser(@Nullable String id, @Nullable String name) {
entry.setUser(id);
public AuditLogBuilder forUser(@Nullable String userId, @Nullable String name) {
entry.setUser(userId);
entry.setUserName(name);

return this;
Expand All @@ -102,36 +101,36 @@ public AuditLogBuilder forUser(@Nullable String id, @Nullable String name) {
*/
@CheckReturnValue
public AuditLogBuilder causedByCurrentUser() {
UserInfo user = UserContext.getCurrentUser();
return causedByUser(user.getUserId(), user.getProtocolUsername());
UserInfo userInfo = UserContext.getCurrentUser();
return causedByUser(userInfo.getUserId(), userInfo.getProtocolUsername());
}

/**
* Marks the entry as caused by the given user.
*
* @param id the ID of the user
* @param name the name of the user
* @param userId the ID of the user
* @param userName the name of the user
* @return the builder for fluent method calls
*/
@CheckReturnValue
public AuditLogBuilder causedByUser(@Nullable String id, @Nullable String name) {
entry.setCausedByUser(id);
entry.setCausedByUserName(name);
public AuditLogBuilder causedByUser(@Nullable String userId, @Nullable String userName) {
entry.setCausedByUser(userId);
entry.setCausedByUserName(userName);

return this;
}

/**
* Creates the entry for the given tenant.
*
* @param id the ID of the tenant
* @param name the name of the tenant
* @param tenantId the ID of the tenant
* @param tenantName the name of the tenant
* @return the builder for fluent method calls
*/
@CheckReturnValue
public AuditLogBuilder forTenant(@Nullable String id, @Nullable String name) {
entry.setTenant(id);
entry.setTenantName(name);
public AuditLogBuilder forTenant(@Nullable String tenantId, @Nullable String tenantName) {
entry.setTenant(tenantId);
entry.setTenantName(tenantName);

return this;
}
Expand Down Expand Up @@ -166,8 +165,8 @@ public void log() {
elastic.update(entry);
logToSyslog();
}
} catch (Exception e) {
Exceptions.ignore(e);
} catch (Exception exception) {
Exceptions.ignore(exception);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import sirius.biz.jobs.JobFactory;
import sirius.biz.tycho.QuickAction;
import sirius.kernel.async.CallContext;
import sirius.kernel.di.std.PriorityParts;
import sirius.kernel.di.std.Register;
import sirius.web.http.WebContext;
Expand Down Expand Up @@ -55,7 +54,7 @@ public Stream<JobFactory> getAvailableJobs() {

@Override
public void computeQuickAction(VirtualFile virtualFile, Consumer<QuickAction> consumer) {
String uri = CallContext.getCurrent().get(WebContext.class).getRequest().uri();
String uri = WebContext.getCurrent().getRequest().uri();
getAvailableJobs().filter(jobFactory -> jobFactory.generatePresetUrl(uri, virtualFile) != null)
.forEach(jobFactory -> consumer.accept(new QuickAction().withIcon("fa fa-cogs")
.withLabel(jobFactory.getLabel())
Expand Down
Loading

0 comments on commit 82d839c

Please sign in to comment.