generated from hmcts/spring-boot-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into PO-424-courts-ref-data
- Loading branch information
Showing
19 changed files
with
648 additions
and
14 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
src/main/java/uk/gov/hmcts/opal/scheduler/aspect/LogExecutionTime.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/uk/gov/hmcts/opal/scheduler/aspect/LogExecutionTimeAspect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/java/uk/gov/hmcts/opal/scheduler/job/inbound/AutoCashJob.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/uk/gov/hmcts/opal/scheduler/job/inbound/AutoCheckJob.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/uk/gov/hmcts/opal/scheduler/job/outbound/AllPayArchiveJob.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/uk/gov/hmcts/opal/scheduler/service/AllPayArchiveService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/uk/gov/hmcts/opal/scheduler/service/AutoCashService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/uk/gov/hmcts/opal/scheduler/service/AutoCheckService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/test/java/uk/gov/hmcts/opal/scheduler/aspect/LogExecutionTimeAspectTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.