diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/SmsConsumerThread.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/SmsConsumerThread.java index a92c600f4f3f..d3802217dd8c 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/SmsConsumerThread.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/SmsConsumerThread.java @@ -35,8 +35,6 @@ import org.hisp.dhis.sms.incoming.IncomingSmsListener; import org.hisp.dhis.sms.incoming.IncomingSmsService; import org.hisp.dhis.sms.incoming.SmsMessageStatus; -import org.hisp.dhis.user.AuthenticationService; -import org.hisp.dhis.user.User; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Component; @@ -54,8 +52,6 @@ public class SmsConsumerThread { private final IncomingSmsService incomingSmsService; - private final AuthenticationService authenticationService; - public void spawnSmsConsumer() { IncomingSms message = messageQueue.get(); @@ -63,9 +59,6 @@ public void spawnSmsConsumer() { log.info("Received SMS: " + message.getText()); try { - User createdBy = message.getCreatedBy(); - authenticationService.obtainAuthentication(createdBy.getUid()); - for (IncomingSmsListener listener : listeners) { if (listener.accept(message)) { listener.receive(message); @@ -85,8 +78,6 @@ public void spawnSmsConsumer() { message.setStatus(SmsMessageStatus.FAILED); message.setParsed(false); } finally { - authenticationService.clearAuthentication(); - messageQueue.remove(message); incomingSmsService.update(message); diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/SmsPublisher.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/SmsPublisher.java index b16ab650b3bc..3d08fe9875df 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/SmsPublisher.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/SmsPublisher.java @@ -29,6 +29,7 @@ import java.util.concurrent.ScheduledFuture; import lombok.RequiredArgsConstructor; +import org.hisp.dhis.user.AuthenticationService; import org.springframework.scheduling.TaskScheduler; import org.springframework.stereotype.Component; @@ -41,12 +42,24 @@ public class SmsPublisher { private final TaskScheduler taskScheduler; + private final AuthenticationService authenticationService; + private ScheduledFuture future; public void start() { messageQueue.initialize(); - future = taskScheduler.scheduleWithFixedDelay(smsConsumer::spawnSmsConsumer, 5000); + future = + taskScheduler.scheduleWithFixedDelay( + () -> { + try { + authenticationService.obtainSystemAuthentication(); + smsConsumer.spawnSmsConsumer(); + } finally { + authenticationService.clearAuthentication(); + } + }, + 5000); } public void stop() { diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/listener/CommandSMSListener.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/listener/CommandSMSListener.java index a58ca27aae5e..dfb32de40123 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/listener/CommandSMSListener.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/listener/CommandSMSListener.java @@ -58,7 +58,6 @@ import org.hisp.dhis.sms.incoming.IncomingSmsService; import org.hisp.dhis.sms.incoming.SmsMessageStatus; import org.hisp.dhis.system.util.SmsUtils; -import org.hisp.dhis.user.CurrentUserUtil; import org.hisp.dhis.user.User; import org.hisp.dhis.user.UserService; import org.springframework.transaction.annotation.Transactional; @@ -238,7 +237,7 @@ protected void register( Enrollment enrollment = enrollments.get(0); UserInfoSnapshot currentUserInfo = - UserInfoSnapshot.from(CurrentUserUtil.getCurrentUserDetails()); + UserInfoSnapshot.from(userService.getUser(sms.getCreatedBy().getId())); Event event = new Event(); event.setOrganisationUnit(ous.iterator().next()); diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/listener/ProgramStageDataEntrySMSListener.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/listener/ProgramStageDataEntrySMSListener.java index 0c6e186acc35..5a2463ab1942 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/listener/ProgramStageDataEntrySMSListener.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/listener/ProgramStageDataEntrySMSListener.java @@ -152,7 +152,7 @@ private List getTrackedEntityByPhoneNumber( List trackedEntities = new ArrayList<>(); - attributes.parallelStream() + attributes.stream() .map(attr -> getParams(attr, sms, command.getProgram(), ous)) .forEach( param ->