Skip to content

Commit 992bcae

Browse files
authored
Merge pull request #405 from RADAR-base/release-2.1.1
Release 2.2.0
2 parents 59d3334 + b9df04d commit 992bcae

File tree

16 files changed

+163
-168
lines changed

16 files changed

+163
-168
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ apply plugin: 'io.spring.dependency-management'
1313
apply plugin: 'scala'
1414

1515
group = 'org.radarbase'
16-
version = '2.1.0'
16+
version = '2.2.0'
1717
sourceCompatibility = 11
1818

1919
repositories {

src/main/java/org/radarbase/appserver/config/ApplicationConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@
2626
import org.springframework.context.annotation.Configuration;
2727
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
2828
import org.springframework.scheduling.annotation.EnableAsync;
29+
import org.springframework.scheduling.annotation.EnableScheduling;
2930
import org.springframework.transaction.annotation.EnableTransactionManagement;
3031

3132
@Configuration
3233
@EnableJpaAuditing
3334
@EnableConfigurationProperties({FcmServerConfig.class})
3435
@EnableTransactionManagement
3536
@EnableAsync
37+
@EnableScheduling
3638
public class ApplicationConfig {}

src/main/java/org/radarbase/appserver/controller/FcmNotificationController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
@RestController
5151
public class FcmNotificationController {
5252

53-
private transient FcmNotificationService notificationService;
53+
private final transient FcmNotificationService notificationService;
5454

5555
public FcmNotificationController(FcmNotificationService notificationService) {
5656
this.notificationService = notificationService;

src/main/java/org/radarbase/appserver/converter/UserConverter.java

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
package org.radarbase.appserver.converter;
2323

24+
import java.time.Instant;
2425
import java.time.LocalDateTime;
2526
import java.time.ZoneOffset;
2627
import org.radarbase.appserver.dto.fcm.FcmUserDto;
@@ -40,20 +41,11 @@
4041
public class UserConverter implements Converter<User, FcmUserDto> {
4142

4243
public static UserMetrics getValidUserMetrics(FcmUserDto fcmUserDto) {
43-
UserMetrics userMetrics;
44-
if (fcmUserDto.getLastOpened() == null && fcmUserDto.getLastDelivered() == null) {
45-
userMetrics = new UserMetrics(LocalDateTime.now().toInstant(ZoneOffset.UTC), null);
46-
} else if (fcmUserDto.getLastDelivered() == null) {
47-
userMetrics = new UserMetrics(fcmUserDto.getLastOpened(), null);
48-
} else if (fcmUserDto.getLastOpened() == null) {
49-
userMetrics =
50-
new UserMetrics(
51-
LocalDateTime.now().toInstant(ZoneOffset.UTC), fcmUserDto.getLastDelivered());
52-
} else {
53-
userMetrics = new UserMetrics(fcmUserDto.getLastOpened(), fcmUserDto.getLastDelivered());
44+
Instant lastOpened = fcmUserDto.getLastOpened();
45+
if (lastOpened == null) {
46+
lastOpened = Instant.now();
5447
}
55-
56-
return userMetrics;
48+
return new UserMetrics(lastOpened, fcmUserDto.getLastDelivered());
5749
}
5850

5951
@Override

src/main/java/org/radarbase/appserver/repository/UserRepository.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import org.springframework.data.jpa.repository.JpaRepository;
2929
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
3030
import org.springframework.stereotype.Repository;
31+
import org.springframework.transaction.annotation.Propagation;
32+
import org.springframework.transaction.annotation.Transactional;
3133

3234
/** @author yatharthranjan */
3335
@Repository
@@ -43,4 +45,7 @@ public interface UserRepository extends JpaRepository<User, Long> {
4345
Optional<User> findByFcmToken(String fcmToken);
4446

4547
void deleteById(@NotNull Long id);
48+
49+
@Transactional(propagation= Propagation.REQUIRES_NEW)
50+
User save(User user);
4651
}

src/main/java/org/radarbase/appserver/service/NotificationStateEventService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ public NotificationStateEventService(
7373

7474
@Transactional
7575
public void addNotificationStateEvent(NotificationStateEvent notificationStateEvent) {
76+
if (notificationStateEvent.getState() == MessageState.CANCELLED) {
77+
// the notification will be removed shortly
78+
return;
79+
}
7680
notificationStateEventRepository.save(notificationStateEvent);
7781
}
7882

src/main/java/org/radarbase/appserver/service/QuestionnaireScheduleService.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
4444
import org.springframework.context.annotation.Scope;
4545
import org.springframework.data.jpa.domain.Specification;
46+
import org.springframework.scheduling.annotation.Scheduled;
4647
import org.springframework.stereotype.Service;
4748
import org.springframework.transaction.annotation.Transactional;
4849

@@ -83,14 +84,8 @@ public QuestionnaireScheduleService(ProtocolGenerator protocolGenerator, UserRep
8384
this.taskRepository = taskRepository;
8485
this.protocolGenerator = protocolGenerator;
8586
this.scheduleGeneratorService = scheduleGeneratorService;
86-
this.init();
8787
}
8888

89-
public void init() {
90-
ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);
91-
executorService.scheduleWithFixedDelay(
92-
this::generateAllSchedules, 1, 1, TimeUnit.HOURS);
93-
}
9489

9590
@Transactional
9691
public List<Task> getTasksUsingProjectIdAndSubjectId(String projectId, String subjectId) {
@@ -148,6 +143,11 @@ public Schedule generateScheduleUsingProjectIdAndSubjectId(String projectId, Str
148143
@Transactional
149144
public Schedule generateScheduleForUser(User user) {
150145
Protocol protocol = protocolGenerator.getProtocolForSubject(user.getSubjectId());
146+
if (protocol == null) {
147+
Schedule emptySchedule = new Schedule();
148+
subjectScheduleMap.put(user.getSubjectId(), emptySchedule);
149+
return emptySchedule;
150+
}
151151
Schedule prevSchedule = getScheduleForSubject(user.getSubjectId());
152152
String prevTimezone = prevSchedule.getTimezone() != null ? prevSchedule.getTimezone() : user.getTimezone();
153153
if (!Objects.equals(prevSchedule.getVersion(), protocol.getVersion()) || !prevTimezone.equals(user.getTimezone())) {
@@ -174,14 +174,15 @@ public Schedule generateScheduleUsingProjectIdAndSubjectIdAndAssessment(String p
174174
return schedule;
175175
}
176176

177-
public Map<String, Schedule> generateAllSchedules() {
177+
@Scheduled(fixedRate = 3_600_000)
178+
public void generateAllSchedules() {
178179
List<User> users = this.userRepository.findAll();
179180

180-
return users.parallelStream()
181+
users.parallelStream()
181182
.map(u -> {
182183
Schedule schedule = this.generateScheduleForUser(u);
183184
return new Pair<String, Schedule>(u.getSubjectId(), schedule);
184-
}).collect(Collectors.toMap(Pair::getKey, Pair::getValue));
185+
});
185186
}
186187

187188
public Schedule getScheduleForSubject(String subjectId) {

0 commit comments

Comments
 (0)