From 842566d788b7db7566a53130ffeb832f825e9aea Mon Sep 17 00:00:00 2001 From: Shrey Bansod Date: Wed, 20 Nov 2024 13:19:46 +0530 Subject: [PATCH] Updated formatting --- .../gateway/service/did/GitDidUploader.java | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/main/java/eu/europa/ec/dgc/gateway/service/did/GitDidUploader.java b/src/main/java/eu/europa/ec/dgc/gateway/service/did/GitDidUploader.java index 568517ab..16f9c5b2 100644 --- a/src/main/java/eu/europa/ec/dgc/gateway/service/did/GitDidUploader.java +++ b/src/main/java/eu/europa/ec/dgc/gateway/service/did/GitDidUploader.java @@ -20,6 +20,7 @@ package eu.europa.ec.dgc.gateway.service.did; +import eu.europa.ec.dgc.gateway.config.DgcConfigProperties; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -28,16 +29,13 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.time.Instant; - +import lombok.extern.slf4j.Slf4j; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.stereotype.Service; -import eu.europa.ec.dgc.gateway.config.DgcConfigProperties; -import lombok.extern.slf4j.Slf4j; - @ConditionalOnExpression("'${dgc.did.didUploadProvider}'.contains('git')") @Service @Slf4j @@ -52,13 +50,13 @@ public GitDidUploader(DgcConfigProperties configProperties) { @Override public void uploadDid(byte[] content) { - Path targetDirectory = Paths.get(configProperties.getDid().getGit().getWorkdir() - + File.separator - + configProperties.getDid().getGit().getPrefix()); - - deleteDirectoryAndContents(configProperties.getDid().getGit().getWorkdir()); - - try { + Path targetDirectory = Paths.get(configProperties.getDid().getGit().getWorkdir() + + File.separator + + configProperties.getDid().getGit().getPrefix()); + + deleteDirectoryAndContents(configProperties.getDid().getGit().getWorkdir()); + + try { Git.cloneRepository() .setURI(configProperties.getDid().getGit().getUrl()) .setDirectory(new File(configProperties.getDid().getGit().getWorkdir())) @@ -70,14 +68,15 @@ public void uploadDid(byte[] content) { log.error("Failed to clone repository {}: {}", configProperties.getDid().getGit().getUrl(), e.getMessage()); } - - try { - File outputFile = new File(targetDirectory.toString() + File.separator + "did.json"); - try (FileOutputStream outputStream = new FileOutputStream(outputFile)) { - outputStream.write(content); - } + + try { + File outputFile = new File(targetDirectory.toString() + File.separator + "did.json"); + try (FileOutputStream outputStream = new FileOutputStream(outputFile)) { + outputStream.write(content); + } Git git = Git.open(new File(configProperties.getDid().getGit().getWorkdir())); - git.add().addFilepattern(configProperties.getDid().getGit().getPrefix() + File.separator + outputFile.getName()).call(); + git.add().addFilepattern(configProperties.getDid().getGit().getPrefix() + + File.separator + outputFile.getName()).call(); git.commit().setMessage("Added DID files on " + Instant.now()).call(); git.push().setCredentialsProvider(new UsernamePasswordCredentialsProvider( "anonymous", configProperties.getDid().getGit().getPat())).call(); @@ -87,7 +86,13 @@ public void uploadDid(byte[] content) { } catch (GitAPIException | IOException e) { log.error("Error during Git commit & push: {}",e.getMessage()); } - + + } + + @Override + public void uploadDid(String subContainer, byte[] content) { + + log.trace("Upload not required"); } private void deleteDirectoryAndContents(String directoryPath) { @@ -113,11 +118,6 @@ private void deleteDirectoryAndContents(String directoryPath) { } else { log.info("Directory {} does not exist, skippig deletion", dir); } - } + } - @Override - public void uploadDid(String subContainer, byte[] content) { - - log.trace("Upload not required"); - } }