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.
PO-282: Automatically create required locations on Azure (#348)
- Loading branch information
1 parent
36a55fe
commit 2ed6784
Showing
16 changed files
with
537 additions
and
41 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package uk.gov.hmcts.opal.sftp; | ||
|
||
public enum SftpDirection { | ||
INBOUND, | ||
OUTBOUND | ||
} | ||
|
45 changes: 45 additions & 0 deletions
45
src/main/java/uk/gov/hmcts/opal/sftp/SftpInboundService.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.sftp; | ||
|
||
import jakarta.annotation.PostConstruct; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.integration.sftp.session.DefaultSftpSessionFactory; | ||
import org.springframework.stereotype.Service; | ||
import uk.gov.hmcts.opal.sftp.config.SftpConnection; | ||
|
||
import java.io.InputStream; | ||
import java.util.function.Consumer; | ||
|
||
import static uk.gov.hmcts.opal.sftp.SftpLocation.getInboundLocations; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class SftpInboundService { | ||
|
||
private final DefaultSftpSessionFactory inboundSessionFactory; | ||
private final SftpService sftpService; | ||
private final SftpConnection inboundConnection; | ||
|
||
public void uploadFile(byte[] fileBytes, String path, String fileName) { | ||
sftpService.uploadFile(inboundSessionFactory, fileBytes, path, fileName); | ||
} | ||
|
||
public boolean downloadFile(String path, String fileName, Consumer<InputStream> fileProcessor) { | ||
return sftpService.downloadFile(inboundSessionFactory, path, fileName, fileProcessor); | ||
} | ||
|
||
public boolean deleteFile(String path, String fileName) { | ||
return sftpService.deleteFile(inboundSessionFactory, path, fileName); | ||
} | ||
|
||
@PostConstruct | ||
public void createSftpLocations() { | ||
if (inboundConnection.isCreateSubLocations()) { | ||
getInboundLocations() | ||
.forEach(sftpLocation -> | ||
this.sftpService.createDirectoryIfNotExists(inboundSessionFactory, sftpLocation) | ||
); | ||
} | ||
} | ||
} |
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,48 @@ | ||
package uk.gov.hmcts.opal.sftp; | ||
|
||
import lombok.Getter; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import static uk.gov.hmcts.opal.sftp.SftpDirection.INBOUND; | ||
import static uk.gov.hmcts.opal.sftp.SftpDirection.OUTBOUND; | ||
|
||
@Getter | ||
public enum SftpLocation { | ||
|
||
AUTO_CHEQUES(INBOUND, "auto-cheque", "Comes from OAGS (pushed)"), | ||
AUTO_CASH(INBOUND, "auto-cash", "Comes from OAGS (pushed)"), | ||
NATWEST(INBOUND, "natwest", "Comes from BAIS (pulled)"), | ||
ALL_PAY_BT_BARCLAY_CARD(INBOUND, "allpay", "Comes from BAIS (pulled)"), | ||
DWP_BAILIFFS(INBOUND, "dwp-bailiffs", "Comes from BAIS (pulled)"), | ||
|
||
ALL_PAY(OUTBOUND, "allpay", "Goes to BAIS (pushed)"), | ||
ARCHIVE(OUTBOUND, "allpay-archive", "Goes to OAGS (pushed)"); | ||
|
||
private final SftpDirection direction; | ||
private final String path; | ||
private final String description; | ||
|
||
SftpLocation(SftpDirection direction, String path, String description) { | ||
this.direction = direction; | ||
this.path = path; | ||
this.description = description; | ||
} | ||
|
||
public static List<SftpLocation> getLocations(SftpDirection direction) { | ||
return Arrays.stream(SftpLocation.values()) | ||
.filter(location -> location.getDirection() == direction) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
public static List<SftpLocation> getInboundLocations() { | ||
return getLocations(INBOUND); | ||
} | ||
|
||
public static List<SftpLocation> getOutboundLocations() { | ||
return getLocations(OUTBOUND); | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/uk/gov/hmcts/opal/sftp/SftpOutboundService.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.sftp; | ||
|
||
import jakarta.annotation.PostConstruct; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.integration.sftp.session.DefaultSftpSessionFactory; | ||
import org.springframework.stereotype.Service; | ||
import uk.gov.hmcts.opal.sftp.config.SftpConnection; | ||
|
||
import java.io.InputStream; | ||
import java.util.function.Consumer; | ||
|
||
import static uk.gov.hmcts.opal.sftp.SftpLocation.getOutboundLocations; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class SftpOutboundService { | ||
|
||
private final DefaultSftpSessionFactory outboundSessionFactory; | ||
private final SftpService sftpService; | ||
private final SftpConnection outboundConnection; | ||
|
||
public void uploadFile(byte[] fileBytes, String path, String fileName) { | ||
sftpService.uploadFile(outboundSessionFactory, fileBytes, path, fileName); | ||
} | ||
|
||
public boolean downloadFile(String path, String fileName, Consumer<InputStream> fileProcessor) { | ||
return sftpService.downloadFile(outboundSessionFactory, path, fileName, fileProcessor); | ||
} | ||
|
||
public boolean deleteFile(String path, String fileName) { | ||
return sftpService.deleteFile(outboundSessionFactory, path, fileName); | ||
} | ||
|
||
@PostConstruct | ||
public void createSftpLocations() { | ||
if (outboundConnection.isCreateSubLocations()) { | ||
getOutboundLocations() | ||
.forEach(sftpLocation -> | ||
this.sftpService.createDirectoryIfNotExists(outboundSessionFactory, sftpLocation) | ||
); | ||
} | ||
} | ||
} |
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
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
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
Oops, something went wrong.