Skip to content

Commit

Permalink
Merge branch '2.40' into DHIS2-18599-2.40
Browse files Browse the repository at this point in the history
  • Loading branch information
ameenhere authored Dec 20, 2024
2 parents 7d80c8f + cd9dd5e commit 04d0c12
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 275 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@
import java.util.Collections;
import java.util.Date;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.hisp.dhis.common.BaseIdentifiableObject;
import org.hisp.dhis.option.OptionService;
import org.hisp.dhis.program.ProgramInstance;
import org.hisp.dhis.program.notification.ProgramTemplateVariable;
import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
Expand Down Expand Up @@ -78,6 +82,8 @@ public class ProgramNotificationMessageRenderer
private static final Set<ExpressionType> SUPPORTED_EXPRESSION_TYPES =
ImmutableSet.of(ExpressionType.TRACKED_ENTITY_ATTRIBUTE, ExpressionType.VARIABLE);

@Autowired private OptionService optionService;

// -------------------------------------------------------------------------
// Overrides
// -------------------------------------------------------------------------
Expand All @@ -97,9 +103,7 @@ protected Map<String, String> resolveTrackedEntityAttributeValues(

return entity.getEntityInstance().getTrackedEntityAttributeValues().stream()
.filter(av -> attributeKeys.contains(av.getAttribute().getUid()))
.collect(
Collectors.toMap(
av -> av.getAttribute().getUid(), ProgramNotificationMessageRenderer::filterValue));
.collect(Collectors.toMap(av -> av.getAttribute().getUid(), this::filterValue));
}

@Override
Expand All @@ -123,7 +127,7 @@ protected Map<String, String> resolveDataElementValues(
// Internal methods
// -------------------------------------------------------------------------

private static String filterValue(TrackedEntityAttributeValue av) {
private String filterValue(TrackedEntityAttributeValue av) {
String value = av.getPlainValue();

if (value == null) {
Expand All @@ -133,9 +137,12 @@ private static String filterValue(TrackedEntityAttributeValue av) {
// If the AV has an OptionSet -> substitute value with the name of the
// Option
if (av.getAttribute().hasOptionSet()) {
value = av.getAttribute().getOptionSet().getOptionByCode(value).getName();
value =
Optional.ofNullable(optionService.getOptionByCode(value))
.map(BaseIdentifiableObject::getName)
.orElse(MISSING_VALUE_REPLACEMENT);
}

return value != null ? value : MISSING_VALUE_REPLACEMENT;
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,18 @@
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.hisp.dhis.common.BaseIdentifiableObject;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.eventdatavalue.EventDataValue;
import org.hisp.dhis.option.OptionService;
import org.hisp.dhis.program.ProgramStageInstance;
import org.hisp.dhis.program.notification.ProgramStageTemplateVariable;
import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
Expand Down Expand Up @@ -110,6 +114,8 @@ public class ProgramStageNotificationMessageRenderer
ExpressionType.VARIABLE,
ExpressionType.DATA_ELEMENT);

@Autowired private OptionService optionService;

// -------------------------------------------------------------------------
// Singleton instance
// -------------------------------------------------------------------------
Expand Down Expand Up @@ -140,10 +146,7 @@ protected Map<String, String> resolveTrackedEntityAttributeValues(
.getTrackedEntityAttributeValues()
.stream()
.filter(av -> attributeKeys.contains(av.getAttribute().getUid()))
.collect(
Collectors.toMap(
av -> av.getAttribute().getUid(),
ProgramStageNotificationMessageRenderer::filterValue));
.collect(Collectors.toMap(av -> av.getAttribute().getUid(), this::filterValue));
}

@Override
Expand Down Expand Up @@ -178,7 +181,7 @@ protected Set<ExpressionType> getSupportedExpressionTypes() {
// Internal methods
// -------------------------------------------------------------------------

private static String filterValue(TrackedEntityAttributeValue av) {
private String filterValue(TrackedEntityAttributeValue av) {
String value = av.getPlainValue();

if (value == null) {
Expand All @@ -188,13 +191,16 @@ private static String filterValue(TrackedEntityAttributeValue av) {
// If the AV has an OptionSet -> substitute value with the name of the
// Option
if (av.getAttribute().hasOptionSet()) {
value = av.getAttribute().getOptionSet().getOptionByCode(value).getName();
value =
Optional.ofNullable(optionService.getOptionByCode(value))
.map(BaseIdentifiableObject::getName)
.orElse(MISSING_VALUE_REPLACEMENT);
}

return value != null ? value : MISSING_VALUE_REPLACEMENT;
return value;
}

private static String filterValue(EventDataValue dv, DataElement dataElement) {
private String filterValue(EventDataValue dv, DataElement dataElement) {
String value = dv.getValue();

if (value == null) {
Expand All @@ -204,9 +210,12 @@ private static String filterValue(EventDataValue dv, DataElement dataElement) {
// If the DV has an OptionSet -> substitute value with the name of the
// Option
if (dataElement != null && dataElement.hasOptionSet()) {
value = dataElement.getOptionSet().getOptionByCode(value).getName();
value =
Optional.ofNullable(optionService.getOptionByCode(value))
.map(BaseIdentifiableObject::getName)
.orElse(MISSING_VALUE_REPLACEMENT);
}

return value != null ? value : MISSING_VALUE_REPLACEMENT;
return value;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,11 @@
*/
package org.hisp.dhis.tracker.job;

import java.io.IOException;
import javax.jms.JMSException;
import javax.jms.TextMessage;
import org.hisp.dhis.artemis.MessageManager;
import org.hisp.dhis.artemis.Topics;
import lombok.RequiredArgsConstructor;
import org.hisp.dhis.common.AsyncTaskExecutor;
import org.hisp.dhis.render.RenderService;
import org.hisp.dhis.scheduling.JobConfiguration;
import org.hisp.dhis.scheduling.JobType;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

/**
Expand All @@ -46,29 +40,12 @@
* @author Zubair Asghar
*/
@Component
public class TrackerNotificationMessageManager extends BaseMessageManager {
@RequiredArgsConstructor
public class TrackerNotificationMessageManager {
private final ObjectFactory<TrackerNotificationThread> trackerNotificationThreadObjectFactory;
private final AsyncTaskExecutor taskExecutor;

public TrackerNotificationMessageManager(
MessageManager messageManager,
AsyncTaskExecutor taskExecutor,
RenderService renderService,
ObjectFactory<TrackerNotificationThread> trackerNotificationThreadObjectFactory) {
super(messageManager, taskExecutor, renderService);
this.trackerNotificationThreadObjectFactory = trackerNotificationThreadObjectFactory;
}

@Override
public String getTopic() {
return Topics.TRACKER_IMPORT_NOTIFICATION_TOPIC_NAME;
}

@JmsListener(
destination = Topics.TRACKER_IMPORT_NOTIFICATION_TOPIC_NAME,
containerFactory = "jmsQueueListenerContainerFactory")
public void consume(TextMessage message) throws JMSException, IOException {
TrackerSideEffectDataBundle bundle = toBundle(message);

public void sendNotifications(TrackerSideEffectDataBundle bundle) {
if (bundle == null) {
return;
}
Expand All @@ -84,6 +61,6 @@ public void consume(TextMessage message) throws JMSException, IOException {

notificationThread.setSideEffectDataBundle(bundle);

executeJob(notificationThread);
taskExecutor.executeTask(notificationThread);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,11 @@
*/
package org.hisp.dhis.tracker.job;

import java.io.IOException;
import javax.jms.JMSException;
import javax.jms.TextMessage;
import org.hisp.dhis.artemis.MessageManager;
import org.hisp.dhis.artemis.Topics;
import lombok.RequiredArgsConstructor;
import org.hisp.dhis.common.AsyncTaskExecutor;
import org.hisp.dhis.render.RenderService;
import org.hisp.dhis.scheduling.JobConfiguration;
import org.hisp.dhis.scheduling.JobType;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

/**
Expand All @@ -46,29 +40,12 @@
* @author Zubair Asghar
*/
@Component
public class TrackerRuleEngineMessageManager extends BaseMessageManager {
@RequiredArgsConstructor
public class TrackerRuleEngineMessageManager {
private final ObjectFactory<TrackerRuleEngineThread> trackerRuleEngineThreadObjectFactory;
private final AsyncTaskExecutor taskExecutor;

public TrackerRuleEngineMessageManager(
MessageManager messageManager,
AsyncTaskExecutor taskExecutor,
RenderService renderService,
ObjectFactory<TrackerRuleEngineThread> trackerRuleEngineThreadObjectFactory) {
super(messageManager, taskExecutor, renderService);
this.trackerRuleEngineThreadObjectFactory = trackerRuleEngineThreadObjectFactory;
}

@Override
public String getTopic() {
return Topics.TRACKER_IMPORT_RULE_ENGINE_TOPIC_NAME;
}

@JmsListener(
destination = Topics.TRACKER_IMPORT_RULE_ENGINE_TOPIC_NAME,
containerFactory = "jmsQueueListenerContainerFactory")
public void consume(TextMessage message) throws JMSException, IOException {
TrackerSideEffectDataBundle bundle = toBundle(message);

public void sendRuleEngineNotifications(TrackerSideEffectDataBundle bundle) {
if (bundle == null) {
return;
}
Expand All @@ -83,6 +60,6 @@ public void consume(TextMessage message) throws JMSException, IOException {

notificationThread.setSideEffectDataBundle(bundle);

executeJob(notificationThread);
taskExecutor.executeTask(notificationThread);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class NotificationSideEffectHandlerService implements SideEffectHandlerSe

@Override
public void handleSideEffect(TrackerSideEffectDataBundle sideEffectDataBundle) {
notificationMessageManager.addJob(sideEffectDataBundle);
notificationMessageManager.sendNotifications(sideEffectDataBundle);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class RuleEngineSideEffectHandlerService implements SideEffectHandlerServ

@Override
public void handleSideEffect(TrackerSideEffectDataBundle sideEffectDataBundle) {
ruleEngineMessageManager.addJob(sideEffectDataBundle);
ruleEngineMessageManager.sendRuleEngineNotifications(sideEffectDataBundle);
}

@Override
Expand Down
Loading

0 comments on commit 04d0c12

Please sign in to comment.