use of se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage in project webcert by sklintyg.
the class NotificationTypeConverterTest method testConvert.
@Test
public void testConvert() throws Exception {
final String intygsId = "intygsid";
final LocalDateTime handelsetid = LocalDateTime.now().minusDays(1);
final HandelsekodEnum handelsetyp = HandelsekodEnum.ANDRAT;
final int skickadeFragorTotalt = 8;
final int skickadeFragorHanterade = 7;
final int skickadeFragorBesvarade = 6;
final int skickadeFragorEjBesvarade = 5;
final int mottagnaFragorTotalt = 4;
final int mottagnaFragorHanterade = 3;
final int mottagnaFragorBesvarade = 2;
final int mottagnaFragorEjBesvarade = 1;
final Intyg intyg = buildIntyg();
ArendeCount skickadeFragor = new ArendeCount(skickadeFragorTotalt, skickadeFragorEjBesvarade, skickadeFragorBesvarade, skickadeFragorHanterade);
ArendeCount mottagnaFragor = new ArendeCount(mottagnaFragorTotalt, mottagnaFragorEjBesvarade, mottagnaFragorBesvarade, mottagnaFragorHanterade);
NotificationMessage msg = new NotificationMessage(intygsId, "luse", handelsetid, handelsetyp, "address", "", null, skickadeFragor, mottagnaFragor, SchemaVersion.VERSION_3, "ref");
CertificateStatusUpdateForCareType res = NotificationTypeConverter.convert(msg, intyg);
assertEquals(intyg, res.getIntyg());
assertEquals(HandelsekodEnum.ANDRAT.value(), res.getHandelse().getHandelsekod().getCode());
assertEquals(HandelsekodEnum.ANDRAT.description(), res.getHandelse().getHandelsekod().getDisplayName());
assertEquals(handelsetid, res.getHandelse().getTidpunkt());
assertNotNull(res.getHandelse().getHandelsekod().getCodeSystem());
// handelsekod -> codeSystemName is not valid in schema but incorrectly generated in java class
// therefore we should not populate this field
assertNull(res.getHandelse().getHandelsekod().getCodeSystemName());
assertSkickadeFrågor(skickadeFragorTotalt, skickadeFragorHanterade, skickadeFragorBesvarade, skickadeFragorEjBesvarade, res);
assertMottagnaFragor(mottagnaFragorTotalt, mottagnaFragorHanterade, mottagnaFragorBesvarade, mottagnaFragorEjBesvarade, res);
// Make sure we have a valid Intyg according to service contract
assertEquals(NotificationTypeConverter.TEMPORARY_ARBETSPLATSKOD, res.getIntyg().getSkapadAv().getEnhet().getArbetsplatskod().getExtension());
assertNull(res.getIntyg().getSkapadAv().getEnhet().getEpost());
}
use of se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage in project webcert by sklintyg.
the class NotificationMessageDiscardFilterTest method testReturnsLatestSaved.
@Test
public void testReturnsLatestSaved() throws IOException {
String intygsId = UUID.randomUUID().toString();
LocalDateTime first = LocalDateTime.now().minusSeconds(5);
NotificationMessage nm2 = buildNotificationMessage(intygsId, HandelsekodEnum.ANDRAT, LocalDateTime.now().minusSeconds(10));
NotificationMessage nm1 = buildNotificationMessage(intygsId, HandelsekodEnum.ANDRAT, first);
NotificationMessage nm3 = buildNotificationMessage(intygsId, HandelsekodEnum.ANDRAT, LocalDateTime.now().minusSeconds(15));
List<Message> processed = testee.process(Arrays.asList(to(nm2), to(nm1), to(nm3)));
assertEquals(1, processed.size());
NotificationMessage notificationMessage = om.readValue((String) processed.get(0).getBody(), NotificationMessage.class);
assertEquals(first, notificationMessage.getHandelseTid());
}
use of se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage in project webcert by sklintyg.
the class NotificationMessageDiscardFilterTest method buildNotificationMessage.
private NotificationMessage buildNotificationMessage(String intygsId, HandelsekodEnum ht, LocalDateTime tid) {
NotificationMessage nf = new NotificationMessage();
nf.setIntygsId(intygsId);
nf.setHandelse(ht);
nf.setHandelseTid(tid);
return nf;
}
use of se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage in project webcert by sklintyg.
the class NotificationMessageDiscardFilter method handleAndratNotification.
private void handleAndratNotification(Map<String, List<Message>> latestMessage, Message camelMsg, NotificationMessage msg) {
List<Message> existingMessagesForIntygsId = latestMessage.get(msg.getIntygsId());
// If SIGNERAT entry exists, do nothing
if (existingMessagesForIntygsId.stream().filter(existingMsg -> getNotificationFromBody(existingMsg).getHandelse() == HandelsekodEnum.SIGNAT).count() > 0) {
return;
}
// Extract the existing msg of ANDRAT type if it exists (Can never be more than one)
Message andratMsg = existingMessagesForIntygsId.stream().filter(existingMsg -> getNotificationFromBody(existingMsg).getHandelse() == HandelsekodEnum.ANDRAT).findFirst().orElse(null);
// No existing of type, add.
if (andratMsg == null) {
existingMessagesForIntygsId.add(camelMsg);
} else if (getNotificationFromBody(andratMsg).getHandelseTid().compareTo(msg.getHandelseTid()) < 0) {
// Exists, but older - replace.
existingMessagesForIntygsId.remove(andratMsg);
existingMessagesForIntygsId.add(camelMsg);
}
}
use of se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage in project webcert by sklintyg.
the class NotificationMessageDiscardFilter method handleSigneratNotification.
private void handleSigneratNotification(Map<String, List<Message>> latestMessage, Message camelMsg, NotificationMessage msg) {
// Add it, we need to have it in the list temporarily in case there are subsequent ANDRAT.
latestMessage.get(msg.getIntygsId()).add(camelMsg);
// Remove any "ANDRAT" messages
Iterator<Message> i = latestMessage.get(msg.getIntygsId()).iterator();
while (i.hasNext()) {
Message existingMsg = i.next();
if (getNotificationFromBody(existingMsg).getHandelse() == HandelsekodEnum.ANDRAT) {
i.remove();
}
}
}
Aggregations