introduced ModuleRegistry to easy inter-module dependencies
This commit is contained in:
@@ -19,11 +19,11 @@ import de.srsoftware.configuration.Configuration;
|
||||
import de.srsoftware.tools.Path;
|
||||
import de.srsoftware.tools.SessionToken;
|
||||
import de.srsoftware.umbrella.core.BaseHandler;
|
||||
import de.srsoftware.umbrella.core.ModuleRegistry;
|
||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||
import de.srsoftware.umbrella.core.model.Session;
|
||||
import de.srsoftware.umbrella.core.model.Token;
|
||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||
import de.srsoftware.umbrella.user.api.UserDb;
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
@@ -31,12 +31,12 @@ import org.json.JSONObject;
|
||||
|
||||
public class LegacyApi extends BaseHandler {
|
||||
|
||||
private final UserDb users;
|
||||
private final Configuration config;
|
||||
private final String messageUrl;
|
||||
private final ModuleRegistry registry;
|
||||
|
||||
public LegacyApi(UserDb userDb, Configuration config) {
|
||||
users = userDb;
|
||||
public LegacyApi(ModuleRegistry registry, Configuration config) {
|
||||
this.registry = registry;
|
||||
this.config = config.subset("umbrella.modules").orElseThrow(() -> new RuntimeException("Missing configuration: umbrella.modules"));
|
||||
this.messageUrl = null;
|
||||
}
|
||||
@@ -128,7 +128,7 @@ public class LegacyApi extends BaseHandler {
|
||||
throw new UmbrellaException(400,"Fetching related users not implemented, yet!");
|
||||
}
|
||||
|
||||
Map<Long, UmbrellaUser> userMap = users.list(0, null, ids);
|
||||
Map<Long, UmbrellaUser> userMap = registry.userService().list(0, null, ids);
|
||||
if (arrayPassed || userMap.size() != 1) {
|
||||
var userData = new HashMap<Long, Map<String, Object>>();
|
||||
for (var entry : userMap.entrySet()) userData.put(entry.getKey(),entry.getValue().toMap());
|
||||
@@ -180,7 +180,7 @@ public class LegacyApi extends BaseHandler {
|
||||
}
|
||||
}
|
||||
if (!recipients.isEmpty()){ // replace legacy user ids by user objects in receivers field
|
||||
Map<Long, UmbrellaUser> resp = users.list(0, null, recipients);
|
||||
Map<Long, UmbrellaUser> resp = registry.userService().list(0, null, recipients);
|
||||
data.put("receivers",resp.values().stream().map(UmbrellaUser::toMap).toList());
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ public class LegacyApi extends BaseHandler {
|
||||
var optToken = SessionToken.from(ex).map(Token::of);
|
||||
if (optToken.isPresent()) try{
|
||||
var token = optToken.get();
|
||||
users.dropSession(token);
|
||||
registry.userService().dropSession(token);
|
||||
var expiredToken = new SessionToken(token.toString(),"/", Instant.now().minus(1, DAYS),true);
|
||||
expiredToken.addTo(ex);
|
||||
if (returnTo instanceof String location) return sendRedirect(ex,location);
|
||||
@@ -245,8 +245,8 @@ public class LegacyApi extends BaseHandler {
|
||||
};
|
||||
|
||||
protected Session requestSession(Token token) throws UmbrellaException {
|
||||
var session = users.load(token);
|
||||
session = users.extend(session);
|
||||
var session = registry.userService().load(token);
|
||||
session = registry.userService().extend(session);
|
||||
return session;
|
||||
}
|
||||
|
||||
@@ -280,8 +280,8 @@ public class LegacyApi extends BaseHandler {
|
||||
|
||||
var o = map.get(TOKEN);
|
||||
if (!(o instanceof String token)) throw new UmbrellaException(500,"Request did not contain token!");
|
||||
var session = users.load(Token.of(token));
|
||||
var user = users.load(session);
|
||||
var session = registry.userService().load(Token.of(token));
|
||||
var user = registry.userService().load(session);
|
||||
var userMap = user.toMap();
|
||||
userMap.put(TOKEN,Map.of(TOKEN,token,EXPIRATION,session.expiration().getEpochSecond()));
|
||||
return sendContent(ex,userMap);
|
||||
|
||||
Reference in New Issue
Block a user