Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Survey specific case processing #138

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
10 changes: 10 additions & 0 deletions .mvn/jvm.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
--add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
--add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED
21 changes: 20 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<dependency>
<groupId>uk.gov.ons.ssdc</groupId>
<artifactId>ssdc-rm-common-entity-model</artifactId>
<version>4.13.0-SNAPSHOT</version>
<version>4.14.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>uk.gov.ons.ssdc</groupId>
Expand Down Expand Up @@ -263,9 +263,28 @@
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<groupId>org.apache.maven.plugins</groupId>
<version>3.8.0</version>
<configuration>
<source>17</source>
<target>17</target>
<encoding>UTF-8</encoding>
<compilerArgs>
<arg>-XDcompilePolicy=simple</arg>
<arg>-Xplugin:ErrorProne</arg>
</compilerArgs>
<annotationProcessorPaths>
<path>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId>
<version>2.11.0</version>
</path>
<!-- Other annotation processors go here.

If 'annotationProcessorPaths' is set, processors will no longer be
discovered on the regular -classpath; see also 'Using Error Prone
together with other annotation processors' below. -->
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public EventLogger(EventRepository eventRepository) {
this.eventRepository = eventRepository;
}

public void logCaseEvent(
public Event logCaseEvent(
Case caze,
String eventDescription,
EventType eventType,
Expand All @@ -46,7 +46,7 @@ public void logCaseEvent(
messageTimestamp);
loggedEvent.setCaze(caze);

eventRepository.save(loggedEvent);
return eventRepository.save(loggedEvent);
}

public void logCaseEvent(
Expand All @@ -61,7 +61,7 @@ public void logCaseEvent(
logCaseEvent(caze, eventDescription, eventType, event, messageTimestamp);
}

public void logUacQidEvent(
public Event logUacQidEvent(
UacQidLink uacQidLink,
String eventDescription,
EventType eventType,
Expand All @@ -83,7 +83,7 @@ public void logUacQidEvent(
messageTimestamp);
loggedEvent.setUacQidLink(uacQidLink);

eventRepository.save(loggedEvent);
return eventRepository.save(loggedEvent);
}

private Event buildEvent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,23 @@
import org.springframework.transaction.annotation.Transactional;
import uk.gov.ons.ssdc.caseprocessor.logging.EventLogger;
import uk.gov.ons.ssdc.caseprocessor.model.dto.EventDTO;
import uk.gov.ons.ssdc.caseprocessor.model.repository.FulfilmentToProcessRepository;
import uk.gov.ons.ssdc.caseprocessor.model.dto.PrintFulfilmentDTO;
import uk.gov.ons.ssdc.caseprocessor.service.CaseService;
import uk.gov.ons.ssdc.caseprocessor.service.FulfilmentService;
import uk.gov.ons.ssdc.common.model.entity.Case;
import uk.gov.ons.ssdc.common.model.entity.EventType;
import uk.gov.ons.ssdc.common.model.entity.ExportFileTemplate;
import uk.gov.ons.ssdc.common.model.entity.FulfilmentSurveyExportFileTemplate;
import uk.gov.ons.ssdc.common.model.entity.FulfilmentToProcess;
import uk.gov.ons.ssdc.common.model.entity.Survey;

@MessageEndpoint
public class PrintFulfilmentReceiver {
private final CaseService caseService;
private final EventLogger eventLogger;
private final FulfilmentToProcessRepository fulfilmentToProcessRepository;
private final FulfilmentService fulfilmentService;

public PrintFulfilmentReceiver(
CaseService caseService,
EventLogger eventLogger,
FulfilmentToProcessRepository fulfilmentToProcessRepository) {
CaseService caseService, EventLogger eventLogger, FulfilmentService fulfilmentService) {
this.caseService = caseService;
this.eventLogger = eventLogger;
this.fulfilmentToProcessRepository = fulfilmentToProcessRepository;
this.fulfilmentService = fulfilmentService;
}

@Transactional
Expand All @@ -38,39 +33,17 @@ public void receiveMessage(Message<byte[]> message) {
EventDTO event = convertJsonBytesToEvent(message.getPayload());

Case caze = caseService.getCase(event.getPayload().getPrintFulfilment().getCaseId());
PrintFulfilmentDTO fulfilment = event.getPayload().getPrintFulfilment();

ExportFileTemplate exportFileTemplate =
getAllowedPrintTemplate(event.getPayload().getPrintFulfilment().getPackCode(), caze);

FulfilmentToProcess fulfilmentToProcess = new FulfilmentToProcess();
fulfilmentToProcess.setExportFileTemplate(exportFileTemplate);
fulfilmentToProcess.setCaze(caze);
fulfilmentToProcess.setCorrelationId(event.getHeader().getCorrelationId());
fulfilmentToProcess.setOriginatingUser(event.getHeader().getOriginatingUser());
fulfilmentToProcess.setUacMetadata(event.getPayload().getPrintFulfilment().getUacMetadata());

fulfilmentToProcessRepository.saveAndFlush(fulfilmentToProcess);
fulfilmentService.processPrintFulfilment(
caze,
fulfilment.getPackCode(),
event.getHeader().getCorrelationId(),
event.getHeader().getOriginatingUser(),
fulfilment.getUacMetadata(),
null);

eventLogger.logCaseEvent(
caze, "Print fulfilment requested", EventType.PRINT_FULFILMENT, event, message);
}

private ExportFileTemplate getAllowedPrintTemplate(String packCode, Case caze) {
Survey survey = caze.getCollectionExercise().getSurvey();

for (FulfilmentSurveyExportFileTemplate fulfilmentSurveyExportFileTemplate :
survey.getFulfilmentExportFileTemplates()) {
if (fulfilmentSurveyExportFileTemplate
.getExportFileTemplate()
.getPackCode()
.equals(packCode)) {
return fulfilmentSurveyExportFileTemplate.getExportFileTemplate();
}
}

throw new RuntimeException(
String.format(
"Pack code %s is not allowed as a fulfilment on survey %s",
packCode, survey.getName()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,23 @@
import org.springframework.transaction.annotation.Transactional;
import uk.gov.ons.ssdc.caseprocessor.logging.EventLogger;
import uk.gov.ons.ssdc.caseprocessor.model.dto.EventDTO;
import uk.gov.ons.ssdc.caseprocessor.scheduled.tasks.ScheduledTaskService;
import uk.gov.ons.ssdc.caseprocessor.service.UacService;
import uk.gov.ons.ssdc.common.model.entity.Event;
import uk.gov.ons.ssdc.common.model.entity.EventType;
import uk.gov.ons.ssdc.common.model.entity.UacQidLink;

@MessageEndpoint
public class ReceiptReceiver {
private final UacService uacService;
private final EventLogger eventLogger;
private final ScheduledTaskService scheduledTaskService;

public ReceiptReceiver(UacService uacService, EventLogger eventLogger) {
public ReceiptReceiver(
UacService uacService, EventLogger eventLogger, ScheduledTaskService scheduledTaskService) {
this.uacService = uacService;
this.eventLogger = eventLogger;
this.scheduledTaskService = scheduledTaskService;
}

@Transactional(isolation = Isolation.REPEATABLE_READ)
Expand All @@ -41,6 +46,15 @@ public void receiveMessage(Message<byte[]> message) {
event.getHeader().getOriginatingUser());
}

eventLogger.logUacQidEvent(uacQidLink, "Receipt received", EventType.RECEIPT, event, message);
Event loggedEvent =
eventLogger.logUacQidEvent(
uacQidLink, "Receipt received", EventType.RECEIPT, event, message);

// Problem with this, what happens if the ScheduledTask is removed - this goes boom.
// Although we may want to remove/deativate any UAC that was attached to a dead ScheduledTask?
// Also death
if (uacQidLink.getScheduledTaskId() != null) {
scheduledTaskService.receiptScheduledTask(uacQidLink.getScheduledTaskId(), loggedEvent);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package uk.gov.ons.ssdc.caseprocessor.model.repository;

import java.util.UUID;
import org.springframework.data.jpa.repository.JpaRepository;
import uk.gov.ons.ssdc.common.model.entity.ResponsePeriod;

public interface ResponsePeriodRepository extends JpaRepository<ResponsePeriod, UUID> {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package uk.gov.ons.ssdc.caseprocessor.model.repository;

import java.util.UUID;
import org.springframework.data.jpa.repository.JpaRepository;
import uk.gov.ons.ssdc.common.model.entity.ScheduledTask;

public interface ScheduledTaskRepository extends JpaRepository<ScheduledTask, UUID> {
// List<ScheduledTask> findByrmToActionDateTimeBeforeAndScheduledTaskStateEquals(
// OffsetDateTime now, ScheduledTaskState notStarted);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package uk.gov.ons.ssdc.caseprocessor.scheduled.tasks;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class DateOffSet {
private DateUnit dateUnit;
private int multiplier;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package uk.gov.ons.ssdc.caseprocessor.scheduled.tasks;

// probably use one out the box instead
public enum DateUnit {
DAY,
WEEK,
MONTH
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package uk.gov.ons.ssdc.caseprocessor.scheduled.tasks;

import java.time.OffsetDateTime;
import lombok.Data;

/*
First Stab very simple, Like for Monthly Reminder, PCR, EQ, INCENTIVE.
Then maybe something to get over the idea of run weekly for 4 weeks, then monthly.

Though this could be as simple as specifying

schedule: {
type: REPEAT
spacing: [1W,1W,1W,1W,1M,1M,1M,1M,1M,1M,1M,1M,1M,1M,1M]
scheduleFrom: {
Creation: true
StartDate: Otherwise
},
tasks_every_period [
{
name: reminder,
type: ACTION_WITH_PACKCDDE,
packCode: "CIS_REMINDER"
receipt_required: false,
OffSet: 0D
},
{
name: PCR,
type: ACTION_WITH_PACKCDDE,
packCode: "CIS_PCR"
receipt_required: true,
OffSet: 7D
},
{
name: EQ,
type: ACTION_WITH_PACKCDDE,
packCode: "CIS_EQ",
receipt_required: true,
OffSet: 7D
},
{
name: EQ,
type: INCENTIVE_CHECK(PCR,EQ),
packCode: "CIS_EQ",
receipt_required: false,
OffSet: 8D
},
{
name: EQ,
type: !COMPLETENESS_CHECK(REMINDER,PCR,EQ),
packCode: "CIS_COMPLETE_FAILED",
receipt_required: false,
OffSet: 14D // should be scheduled at Setup, or adjusted at completion of Sending EQ/PCR.
Too complex, for now
}
}

}
*/

@Data
public class ScheduleTemplate {
private String name;
private TemplateType type;
private DateOffSet[] taskSpacing;
private boolean scheduleFromCreate;
private OffsetDateTime startDate;
private Task[] tasks;
}
Loading