Skip to content

Commit

Permalink
fix: use system user
Browse files Browse the repository at this point in the history
  • Loading branch information
teleivo committed Oct 8, 2024
1 parent 7c8ac99 commit ae38f7e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -54,18 +52,13 @@ public class SmsConsumerThread {

private final IncomingSmsService incomingSmsService;

private final AuthenticationService authenticationService;

public void spawnSmsConsumer() {
IncomingSms message = messageQueue.get();

while (message != null) {
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);
Expand All @@ -85,8 +78,6 @@ public void spawnSmsConsumer() {
message.setStatus(SmsMessageStatus.FAILED);
message.setParsed(false);
} finally {
authenticationService.clearAuthentication();

messageQueue.remove(message);

incomingSmsService.update(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private List<TrackedEntity> getTrackedEntityByPhoneNumber(

List<TrackedEntity> trackedEntities = new ArrayList<>();

attributes.parallelStream()
attributes.stream()
.map(attr -> getParams(attr, sms, command.getProgram(), ous))
.forEach(
param ->
Expand Down

0 comments on commit ae38f7e

Please sign in to comment.