Skip to content

Commit

Permalink
Updated formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
shreybansod committed Nov 20, 2024
1 parent 0cacdda commit 842566d
Showing 1 changed file with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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()))
Expand All @@ -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();
Expand All @@ -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) {
Expand All @@ -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");
}
}

0 comments on commit 842566d

Please sign in to comment.