• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

opensrp / opensrp-server-core / #193

17 Oct 2024 10:04AM UTC coverage: 77.377% (-0.2%) from 77.619%
#193

push

github

web-flow
Merge pull request #636 from opensrp/sanitize-spaces-from-productName

sanitize whitespaces from productName

7 of 7 new or added lines in 3 files covered. (100.0%)

27 existing lines in 3 files now uncovered.

8277 of 10697 relevant lines covered (77.38%)

0.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

26.47
/src/main/java/org/opensrp/queue/RabbitMQReceiver.java
1
package org.opensrp.queue;
2

3
import java.io.ByteArrayInputStream;
4
import java.io.InputStream;
5
import java.nio.charset.StandardCharsets;
6

7
import javax.annotation.PostConstruct;
8

9
import org.apache.logging.log4j.LogManager;
10
import org.apache.logging.log4j.Logger;
11
import org.opensrp.service.PlanService;
12
import org.opensrp.service.TaskGenerator;
13
import org.smartregister.domain.PlanDefinition;
14
import org.smartregister.pathevaluator.plan.PlanEvaluator;
15
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
16
import org.springframework.amqp.rabbit.annotation.RabbitListener;
17
import org.springframework.beans.factory.annotation.Autowired;
18
import org.springframework.context.annotation.Profile;
19
import org.springframework.stereotype.Component;
20

21
import com.ibm.fhir.model.format.Format;
22
import com.ibm.fhir.model.parser.FHIRParser;
23
import com.ibm.fhir.model.parser.exception.FHIRParserException;
24
import com.ibm.fhir.model.resource.Resource;
25

26
@Profile("rabbitmq")
27
@Component
28
@RabbitListener(queues = "rabbitmq.task.queue", id = "listener")
29
public class RabbitMQReceiver {
1✔
30

31
        private PlanEvaluator planEvaluator;
32

33
        @Autowired
34
        private PlanService planService;
35
        
36
        @Autowired
37
        private QueueHelper queueHelper;
38
        
39
        //import task generator to guarantee PathEvaluatorLibrary is instantiated first
40
        @SuppressWarnings("unused")
41
        @Autowired
42
        private TaskGenerator taskGenerator;
43

44
        private FHIRParser fhirParser;
45

46
        private static Logger logger = LogManager.getLogger(RabbitMQReceiver.class.toString());
1✔
47

48
        @PostConstruct
49
        public void init() {
50
                fhirParser = FHIRParser.parser(Format.JSON);
1✔
51
        }
1✔
52

53
        @RabbitHandler
54
        public void receiver(PlanEvaluatorMessage planEvaluatorMessage) {
UNCOV
55
                logger.info("PlanEvaluatorMessage listener invoked - Consuming Message with Plan Definition Identifier : " + planEvaluatorMessage.getPlanIdentifier());
×
UNCOV
56
                initializePathEvaluator(planEvaluatorMessage.getUsername());
×
57

UNCOV
58
                if (planEvaluatorMessage != null && planEvaluator != null) {
×
UNCOV
59
                        PlanDefinition planDefinition = planService.getPlan(planEvaluatorMessage.getPlanIdentifier());
×
UNCOV
60
                        if (planDefinition != null && planDefinition.getActions() != null && planEvaluatorMessage.getJurisdiction() != null) {
×
UNCOV
61
                                planEvaluator.evaluatePlan(planDefinition,
×
UNCOV
62
                                                planEvaluatorMessage.getTriggerType(),
×
UNCOV
63
                                                planEvaluatorMessage.getJurisdiction(), null);
×
64
                        }
65
                }
UNCOV
66
        }
×
67

68
        @RabbitHandler
69
        public void receiver(ResourceEvaluatorMessage resourceEvaluatorMessage) {
70
                logger.info("ResourceEvaluatorMessage invoked - Consuming Message");
1✔
71
                if (resourceEvaluatorMessage != null) {
1✔
72
                        InputStream stream = resourceEvaluatorMessage.getResource() != null ? new ByteArrayInputStream(
1✔
73
                                        resourceEvaluatorMessage.getResource().getBytes(StandardCharsets.UTF_8)) : null;
1✔
74
                        try {
75
                                if (stream != null) {
1✔
UNCOV
76
                                        Resource resource = fhirParser.parse(stream);
×
UNCOV
77
                                        logger.info("Resource id is : " + resource.getId());
×
UNCOV
78
                                        initializePathEvaluator(resourceEvaluatorMessage.getUsername());
×
UNCOV
79
                                        if (resource != null && resourceEvaluatorMessage != null
×
UNCOV
80
                                                        && resourceEvaluatorMessage.getAction() != null
×
UNCOV
81
                                                        && resourceEvaluatorMessage.getAction().getCondition() != null
×
82
                                                        && planEvaluator != null) {
83
                                                planEvaluator.evaluateResource(resource, resourceEvaluatorMessage.getQuestionnaireResponse(),
×
84
                                                                resourceEvaluatorMessage.getAction(), resourceEvaluatorMessage.getPlanIdentifier(),
×
85
                                                                resourceEvaluatorMessage.getJurisdictionCode(), resourceEvaluatorMessage.getTriggerType());
×
86
                                        }
87
                                }
88
                        }
UNCOV
89
                        catch (FHIRParserException e) {
×
UNCOV
90
                                logger.error("FHIRParserException occurred " + e.getMessage());
×
UNCOV
91
                        }
×
92
                }
UNCOV
93
        }
×
94

95
        private void initializePathEvaluator(String username) {
UNCOV
96
                if(planEvaluator == null)
×
UNCOV
97
                        planEvaluator = new PlanEvaluator(username, queueHelper);
×
UNCOV
98
        }
×
99

100
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc