Skip to content

Commit

Permalink
Merge branch 'master' into PO-424-courts-ref-data
Browse files Browse the repository at this point in the history
  • Loading branch information
sabahirfan authored Jun 20, 2024
2 parents 84ed813 + 4a26053 commit a5a090f
Show file tree
Hide file tree
Showing 19 changed files with 648 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package uk.gov.hmcts.opal.scheduler.aspect;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface LogExecutionTime {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package uk.gov.hmcts.opal.scheduler.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Aspect
@Component
@Slf4j
public class LogExecutionTimeAspect {

@Around("@annotation(uk.gov.hmcts.opal.scheduler.aspect.LogExecutionTime)")
public Object logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {

long startTime = System.nanoTime();
Object result = joinPoint.proceed();
long endTime = System.nanoTime();

long executionTime = endTime - startTime;

log.info(joinPoint.getSignature() + " executed in " + executionTime + "ms");

return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,7 @@ public void setLogRetentionService(LogRetentionService logRetentionService) {
@Override
public void execute(JobExecutionContext context) {
try {
log.info("Job ** {} ** starting @ {}", context.getJobDetail().getKey().getName(), context.getFireTime());

logRetentionService.deleteExpiredLogAudit();

log.info(
"Job ** {} ** completed. Next job scheduled @ {}",
context.getJobDetail().getKey().getName(),
context.getNextFireTime()
);
} catch (Exception exception) {
log.error(exception.getMessage(), exception);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package uk.gov.hmcts.opal.scheduler.job.inbound;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import uk.gov.hmcts.opal.scheduler.model.CronJob;
import uk.gov.hmcts.opal.scheduler.service.AutoCashService;

@Component
@Getter
@Slf4j
@DisallowConcurrentExecution
public class AutoCashJob implements CronJob {

@Value("${opal.schedule.auto-cash-job.cron}")
private String cronExpression;

@Value("${opal.schedule.auto-cash-job.file-name}")
private String fileName;

@Autowired
private AutoCashService autoCashService;

@Override
public void execute(JobExecutionContext context) {
try {
log.info("Job ** {} ** starting @ {}", context.getJobDetail().getKey().getName(), context.getFireTime());

autoCashService.process(this.fileName);

log.info(
"Job ** {} ** completed. Next job scheduled @ {}",
context.getJobDetail().getKey().getName(),
context.getNextFireTime()
);
} catch (Exception exception) {
log.error(exception.getMessage(), exception);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package uk.gov.hmcts.opal.scheduler.job.inbound;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import uk.gov.hmcts.opal.scheduler.model.CronJob;
import uk.gov.hmcts.opal.scheduler.service.AutoCheckService;

@Component
@Getter
@Slf4j
@DisallowConcurrentExecution
public class AutoCheckJob implements CronJob {

@Value("${opal.schedule.auto-check-job.cron}")
private String cronExpression;

@Value("${opal.schedule.auto-check-job.file-name}")
private String fileName;

@Autowired
private AutoCheckService autoCheckService;

@Override
public void execute(JobExecutionContext context) {
try {
log.info("Job ** {} ** starting @ {}", context.getJobDetail().getKey().getName(), context.getFireTime());

autoCheckService.process(fileName);

log.info(
"Job ** {} ** completed. Next job scheduled @ {}",
context.getJobDetail().getKey().getName(),
context.getNextFireTime()
);
} catch (Exception exception) {
log.error(exception.getMessage(), exception);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package uk.gov.hmcts.opal.scheduler.job.outbound;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import uk.gov.hmcts.opal.scheduler.model.CronJob;
import uk.gov.hmcts.opal.scheduler.service.AllPayArchiveService;

@Component
@Getter
@Slf4j
@DisallowConcurrentExecution
public class AllPayArchiveJob implements CronJob {

@Value("${opal.schedule.all-pay-archive-job.cron}")
private String cronExpression;

@Value("${opal.schedule.all-pay-archive-job.file-name}")
private String fileName;

@Autowired
private AllPayArchiveService allPayArchiveService;

@Override
public void execute(JobExecutionContext context) {
try {
log.info("Job ** {} ** starting @ {}", context.getJobDetail().getKey().getName(), context.getFireTime());

allPayArchiveService.process(fileName);

log.info(
"Job ** {} ** completed. Next job scheduled @ {}",
context.getJobDetail().getKey().getName(),
context.getNextFireTime()
);
} catch (Exception exception) {
log.error(exception.getMessage(), exception);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package uk.gov.hmcts.opal.scheduler.service;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import uk.gov.hmcts.opal.scheduler.aspect.LogExecutionTime;
import uk.gov.hmcts.opal.sftp.SftpOutboundService;

import java.io.InputStream;

import static uk.gov.hmcts.opal.sftp.SftpLocation.ALL_PAY_ARCHIVE;

@Slf4j
@Service
@RequiredArgsConstructor
public class AllPayArchiveService {

private final SftpOutboundService sftpOutboundService;

@LogExecutionTime
public void process(String fileName) {
sftpOutboundService.downloadFile(ALL_PAY_ARCHIVE.getPath(), fileName, this::processFile);
}

public void processFile(InputStream inputStream) {
log.info("Process file contents of the stream.");
//TODO: add file processing logic here.
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package uk.gov.hmcts.opal.scheduler.service;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import uk.gov.hmcts.opal.scheduler.aspect.LogExecutionTime;
import uk.gov.hmcts.opal.sftp.SftpInboundService;

import java.io.InputStream;

import static uk.gov.hmcts.opal.sftp.SftpLocation.AUTO_CASH;

@Slf4j
@Service
@RequiredArgsConstructor
public class AutoCashService {

private final SftpInboundService sftpInboundService;

@LogExecutionTime
public void process(String fileName) {
sftpInboundService.downloadFile(AUTO_CASH.getPath(), fileName, this::processFile);
}

public void processFile(InputStream inputStream) {
log.info("Process file contents of the stream.");
//TODO: add file processing logic here.
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package uk.gov.hmcts.opal.scheduler.service;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import uk.gov.hmcts.opal.scheduler.aspect.LogExecutionTime;
import uk.gov.hmcts.opal.sftp.SftpInboundService;

import java.io.InputStream;

import static uk.gov.hmcts.opal.sftp.SftpLocation.AUTO_CHEQUES;

@Slf4j
@Service
@RequiredArgsConstructor
public class AutoCheckService {

private final SftpInboundService sftpInboundService;

@LogExecutionTime
public void process(String fileName) {
sftpInboundService.downloadFile(AUTO_CHEQUES.getPath(), fileName, this::processFile);
}

public void processFile(InputStream inputStream) {
log.info("Process file contents of the stream.");
//TODO: add file processing logic here.
}
}
2 changes: 1 addition & 1 deletion src/main/java/uk/gov/hmcts/opal/sftp/SftpLocation.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public enum SftpLocation {
DWP_BAILIFFS_ERROR(INBOUND, "dwp-bailiffs/error", "Error processing for DWP bailiffs"),

ALL_PAY(OUTBOUND, "allpay", "Goes to BAIS (pushed)"),
ARCHIVE(OUTBOUND, "allpay-archive", "Goes to OAGS (pushed)");
ALL_PAY_ARCHIVE(OUTBOUND, "allpay-archive", "Goes to OAGS (pushed)");

private final SftpDirection direction;
private final String path;
Expand Down
9 changes: 9 additions & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ opal:
location: ${OPAL_SFTP_OUTBOUND_LOCATION:outbound}
create-sub-locations: ${OPAL_SFTP_OUTBOUND_CREATE_SUB_LOCATIONS:false}
schedule:
auto-check-job:
cron: ${OPAL_AUTO_CHECK_JOB_CRON:0 0 * * * ?}
file-name: ${OPAL_AUTO_CHECK_JOB_FILE_NAME:test.txt}
auto-cash-job:
cron: ${OPAL_AUTO_CASH_JOB_CRON:0 0 * * * ?}
file-name: ${OPAL_AUTO_CASH_JOB_FILE_NAME:test.txt}
all-pay-archive-job:
cron: ${OPAL_ALL_PAY_ARCHIVE_JOB_CRON:0 0 * * * ?}
file-name: ${OPAL_ALL_PAY_ARCHIVE_JOB_FILE_NAME:test.txt}
log-retention-job:
cron: ${OPAL_LOG_RETENTION_JOB_CRON:0 0 * * * ?}
file-handler-job:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package uk.gov.hmcts.opal.scheduler.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

@ExtendWith(MockitoExtension.class)
class LogExecutionTimeAspectTest {

@Mock
private ProceedingJoinPoint joinPoint;

@InjectMocks
private LogExecutionTimeAspect logExecutionTimeAspect;

@Test
void logExecutionTime_shouldLogExecutionTime() throws Throwable {

logExecutionTimeAspect.logExecutionTime(joinPoint);

verify(joinPoint, times(1)).proceed();
}
}
Loading

0 comments on commit a5a090f

Please sign in to comment.