Skip to content

Commit

Permalink
Migrate to latest Play version - addresses #92
Browse files Browse the repository at this point in the history
Injecting request wherever necessary to replace using the context. Still has some work to be done, like removing the AuthProvider from the repositories.
  • Loading branch information
resamsel committed Nov 9, 2020
1 parent 4007133 commit 170c876
Show file tree
Hide file tree
Showing 104 changed files with 1,991 additions and 2,238 deletions.
40 changes: 19 additions & 21 deletions app/actors/ActivityActor.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import actors.ActivityProtocol.Activities;
import actors.ActivityProtocol.Activity;
import akka.actor.UntypedActor;
import akka.actor.AbstractActor;
import dto.Dto;
import models.LogEntry;
import org.slf4j.LoggerFactory;
Expand All @@ -13,7 +13,7 @@
import java.util.stream.Collectors;

@Singleton
public class ActivityActor extends UntypedActor {
public class ActivityActor extends AbstractActor {

public static final String NAME = "activity-actor";

Expand All @@ -24,26 +24,24 @@ public ActivityActor(LogEntryRepository logEntryRepository) {
this.logEntryRepository = logEntryRepository;
}

@SuppressWarnings("unchecked")
@Override
public void onReceive(Object msg) throws Throwable {
if (msg instanceof Activity) {
Activity<Dto> t = (Activity<Dto>) msg;

LoggerFactory.getLogger(ActivityActor.class).debug("onReceive({})", t);

logEntryRepository.create(ActivityActor.fromActivity(t));
} else if (msg instanceof Activities) {
Activities<Dto> t = (Activities<Dto>) msg;

LoggerFactory.getLogger(ActivityActor.class).debug("onReceive({})", t.activities);

logEntryRepository.save(t.activities.stream().map(ActivityActor::fromActivity).collect(
Collectors.toList()));
}
}

private static <T extends Dto> LogEntry fromActivity(Activity<T> t) {
return LogEntry.from(t.type, t.user, t.project, t.dtoClass, t.before, t.after);
}

@Override
public Receive createReceive() {
return receiveBuilder()
.match(Activity.class, t -> {
LoggerFactory.getLogger(ActivityActor.class).debug("onReceive({})", t);

logEntryRepository.create(ActivityActor.fromActivity(t));
})
.match(Activities.class, (t) -> {
LoggerFactory.getLogger(ActivityActor.class).debug("onReceive({})", t.activities);

logEntryRepository.save(((Activities<?>)t).activities.stream().map(ActivityActor::fromActivity).collect(
Collectors.toList()));
})
.build();
}
}
17 changes: 7 additions & 10 deletions app/actors/KeyWordCountActor.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package actors;

import actors.WordCountProtocol.ChangeWordCount;
import akka.actor.UntypedActor;
import akka.actor.AbstractActor;
import services.KeyService;

import javax.inject.Inject;
Expand All @@ -12,7 +12,7 @@
* @version 6 Jun 2017
*/
@Singleton
public class KeyWordCountActor extends UntypedActor {
public class KeyWordCountActor extends AbstractActor {
public static final String NAME = "key-word-count-actor";

private final KeyService keyService;
Expand All @@ -22,14 +22,11 @@ public KeyWordCountActor(KeyService keyService) {
this.keyService = keyService;
}

/**
* {@inheritDoc}
*/
@Override
public void onReceive(Object msg) throws Throwable {
if (msg instanceof ChangeWordCount) {
ChangeWordCount wordCount = (ChangeWordCount) msg;
keyService.increaseWordCountBy(wordCount.id, wordCount.wordCountDiff);
}
public Receive createReceive() {
return receiveBuilder()
.match(ChangeWordCount.class,
wordCount -> keyService.increaseWordCountBy(wordCount.id, wordCount.wordCountDiff, null /* FIXME */))
.build();
}
}
17 changes: 7 additions & 10 deletions app/actors/LocaleWordCountActor.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package actors;

import actors.WordCountProtocol.ChangeWordCount;
import akka.actor.UntypedActor;
import akka.actor.AbstractActor;
import services.LocaleService;

import javax.inject.Inject;
Expand All @@ -12,7 +12,7 @@
* @version 6 Jun 2017
*/
@Singleton
public class LocaleWordCountActor extends UntypedActor {
public class LocaleWordCountActor extends AbstractActor {
public static final String NAME = "locale-word-count-actor";

private final LocaleService localeService;
Expand All @@ -22,14 +22,11 @@ public LocaleWordCountActor(LocaleService localeService) {
this.localeService = localeService;
}

/**
* {@inheritDoc}
*/
@Override
public void onReceive(Object msg) throws Throwable {
if (msg instanceof ChangeWordCount) {
ChangeWordCount wordCount = (ChangeWordCount) msg;
localeService.increaseWordCountBy(wordCount.id, wordCount.wordCountDiff);
}
public Receive createReceive() {
return receiveBuilder()
.match(ChangeWordCount.class,
wordCount -> localeService.increaseWordCountBy(wordCount.id, wordCount.wordCountDiff, null /* FIXME */))
.build();
}
}
69 changes: 33 additions & 36 deletions app/actors/MessageWordCountActor.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import actors.WordCountProtocol.ChangeMessageWordCount;
import actors.WordCountProtocol.ChangeWordCount;
import akka.actor.AbstractActor;
import akka.actor.ActorRef;
import akka.actor.UntypedActor;

import javax.inject.Inject;
import javax.inject.Named;
Expand All @@ -18,7 +18,7 @@
* @version 6 Jun 2017
*/
@Singleton
public class MessageWordCountActor extends UntypedActor {
public class MessageWordCountActor extends AbstractActor {
public static final String NAME = "message-word-count-actor";

private final ActorRef localeWordCountActor;
Expand All @@ -36,41 +36,38 @@ public MessageWordCountActor(@Named(LocaleWordCountActor.NAME) ActorRef localeWo
this.projectWordCountActor = projectWordCountActor;
}

/**
* {@inheritDoc}
*/
@Override
public void onReceive(Object msg) throws Throwable {
if (msg instanceof ChangeMessageWordCount) {
ChangeMessageWordCount wordCount = (ChangeMessageWordCount) msg;
public Receive createReceive() {
return receiveBuilder()
.match(ChangeMessageWordCount.class, wordCount -> {
if (wordCount.projectId != null)
projectWordCountActor.tell(
new ChangeWordCount(wordCount.projectId, wordCount.wordCount, wordCount.wordCountDiff),
self());
if (wordCount.localeId != null)
localeWordCountActor.tell(
new ChangeWordCount(wordCount.localeId, wordCount.wordCount, wordCount.wordCountDiff),
self());
if (wordCount.keyId != null)
keyWordCountActor.tell(
new ChangeWordCount(wordCount.keyId, wordCount.wordCount, wordCount.wordCountDiff),
self());
})
.match(Collection.class, t -> {
Collection<ChangeMessageWordCount> wordCounts = (Collection<ChangeMessageWordCount>) t;

if (wordCount.projectId != null)
projectWordCountActor.tell(
new ChangeWordCount(wordCount.projectId, wordCount.wordCount, wordCount.wordCountDiff),
self());
if (wordCount.localeId != null)
localeWordCountActor.tell(
new ChangeWordCount(wordCount.localeId, wordCount.wordCount, wordCount.wordCountDiff),
self());
if (wordCount.keyId != null)
keyWordCountActor.tell(
new ChangeWordCount(wordCount.keyId, wordCount.wordCount, wordCount.wordCountDiff),
self());
} else if (msg instanceof Collection) {
@SuppressWarnings("unchecked")
Collection<ChangeMessageWordCount> wordCounts = (Collection<ChangeMessageWordCount>) msg;

wordCounts.stream()
.map(wc -> new ChangeWordCount(wc.projectId, wc.wordCount, wc.wordCountDiff))
.collect(groupingBy(wc -> wc.id, reducing(ChangeWordCount::merge)))
.forEach((projectId, wc) -> projectWordCountActor.tell(wc.get(), null));
wordCounts.stream()
.map(wc -> new ChangeWordCount(wc.localeId, wc.wordCount, wc.wordCountDiff))
.collect(groupingBy(wc -> wc.id, reducing(ChangeWordCount::merge)))
.forEach((localeId, wc) -> localeWordCountActor.tell(wc.get(), null));
wordCounts.stream().map(wc -> new ChangeWordCount(wc.keyId, wc.wordCount, wc.wordCountDiff))
.collect(groupingBy(wc -> wc.id, reducing(ChangeWordCount::merge)))
.forEach((keyId, wc) -> keyWordCountActor.tell(wc.get(), null));
}
wordCounts.stream()
.map(wc -> new ChangeWordCount(wc.projectId, wc.wordCount, wc.wordCountDiff))
.collect(groupingBy(wc -> wc.id, reducing(ChangeWordCount::merge)))
.forEach((projectId, wc) -> projectWordCountActor.tell(wc.get(), null));
wordCounts.stream()
.map(wc -> new ChangeWordCount(wc.localeId, wc.wordCount, wc.wordCountDiff))
.collect(groupingBy(wc -> wc.id, reducing(ChangeWordCount::merge)))
.forEach((localeId, wc) -> localeWordCountActor.tell(wc.get(), null));
wordCounts.stream().map(wc -> new ChangeWordCount(wc.keyId, wc.wordCount, wc.wordCountDiff))
.collect(groupingBy(wc -> wc.id, reducing(ChangeWordCount::merge)))
.forEach((keyId, wc) -> keyWordCountActor.tell(wc.get(), null));
})
.build();
}
}
21 changes: 9 additions & 12 deletions app/actors/NotificationActor.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import actors.NotificationProtocol.FollowNotification;
import actors.NotificationProtocol.PublishNotification;
import akka.actor.UntypedActor;
import akka.actor.AbstractActor;
import services.NotificationService;

import javax.inject.Inject;
import javax.inject.Singleton;

@Singleton
public class NotificationActor extends UntypedActor {
public class NotificationActor extends AbstractActor {

public static final String NAME = "notification-actor";

Expand All @@ -21,15 +21,12 @@ public NotificationActor(NotificationService notificationService) {
}

@Override
public void onReceive(Object msg) throws Throwable {
if (msg instanceof PublishNotification) {
PublishNotification t = (PublishNotification) msg;

notificationService.publish(t.id, t.type, t.name, t.contentId, t.userId, t.projectId);
} else if (msg instanceof FollowNotification) {
FollowNotification t = (FollowNotification) msg;

notificationService.follow(t.userId, t.projectId);
}
public Receive createReceive() {
return receiveBuilder()
.match(PublishNotification.class,
t -> notificationService.publish(t.id, t.type, t.name, t.contentId, t.userId, t.projectId))
.match(FollowNotification.class,
t -> notificationService.follow(t.userId, t.projectId))
.build();
}
}
17 changes: 7 additions & 10 deletions app/actors/ProjectWordCountActor.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package actors;

import actors.WordCountProtocol.ChangeWordCount;
import akka.actor.UntypedActor;
import akka.actor.AbstractActor;
import services.ProjectService;

import javax.inject.Inject;
Expand All @@ -12,7 +12,7 @@
* @version 6 Jun 2017
*/
@Singleton
public class ProjectWordCountActor extends UntypedActor {
public class ProjectWordCountActor extends AbstractActor {
public static final String NAME = "project-word-count-actor";

private final ProjectService projectService;
Expand All @@ -22,14 +22,11 @@ public ProjectWordCountActor(ProjectService projectService) {
this.projectService = projectService;
}

/**
* {@inheritDoc}
*/
@Override
public void onReceive(Object msg) throws Throwable {
if (msg instanceof ChangeWordCount) {
ChangeWordCount wordCount = (ChangeWordCount) msg;
projectService.increaseWordCountBy(wordCount.id, wordCount.wordCountDiff);
}
public Receive createReceive() {
return receiveBuilder()
.match(ChangeWordCount.class,
wordCount -> projectService.increaseWordCountBy(wordCount.id, wordCount.wordCountDiff, null /* FIXME */))
.build();
}
}
2 changes: 1 addition & 1 deletion app/auth/AccessTokenAuthenticator.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public AccessTokenAuthenticator(Injector injector, String clientName) {
public void validate(TokenCredentials credentials, WebContext context) {
init();

AccessToken accessToken = accessTokenService.byKey(credentials.getToken());
AccessToken accessToken = accessTokenService.byKey(credentials.getToken(), null) /* FIXME */;

if (accessToken == null) {
throw new CredentialsException("Could not validate access token");
Expand Down
3 changes: 2 additions & 1 deletion app/auth/CustomCallbackLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ public R perform(C context, Config config, HttpActionAdapter<R, C> httpActionAda
R result = delegate.perform(context, config, httpActionAdapter, defaultUrl, saveInSession, multiProfile, renewSession, client);

try {
// INFO: providing null for request in this context is okay
authProvider.loggedInProfile(context)
.ifPresent(profile -> authProvider.updateUser(profile));
.ifPresent(profile -> authProvider.updateUser(profile, null));
} catch (UserUnregisteredException e) {
return httpActionAdapter.adapt(new SeeOtherAction(routes.Application.indexUi().url() + "/register"), context);
}
Expand Down
12 changes: 6 additions & 6 deletions app/com/gettextresourcebundle/GettextResourceBundle.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
package com.gettextresourcebundle;

import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.text.StringEscapeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -16,7 +16,7 @@

/**
* @author Tom Schaible
*
*
* A resource bundle that is created from a gettext PO file
*/
public class GettextResourceBundle extends ResourceBundle {
Expand All @@ -32,9 +32,9 @@ public GettextResourceBundle(Reader reader) {

/**
* initialize the ResourceBundle from a PO file
*
*
* if
*
*
* @param reader the reader to read the contents of the PO file from
*/
private void init(LineNumberReader reader) {
Expand Down Expand Up @@ -106,7 +106,7 @@ private void init(LineNumberReader reader) {

/*
* (non-Javadoc)
*
*
* @see java.util.ResourceBundle#getKeys()
*/
@Override
Expand All @@ -116,7 +116,7 @@ public Enumeration<String> getKeys() {

/*
* (non-Javadoc)
*
*
* @see java.util.ResourceBundle#handleGetObject(java.lang.String)
*/
@Override
Expand Down
Loading

0 comments on commit 170c876

Please sign in to comment.