aboutsummaryrefslogtreecommitdiffstats
path: root/certServiceClient/src/main/java
diff options
context:
space:
mode:
authorkjaniak <kornel.janiak@nokia.com>2020-07-08 15:19:33 +0200
committerPiotr Marcinkiewicz <piotr.marcinkiewicz@nokia.com>2020-07-13 10:12:50 +0200
commite64680cd62b468a25b763457c2e1d31414081c29 (patch)
tree21ab8e027a6fb62dc606eca155b719772de29612 /certServiceClient/src/main/java
parented1b24390eaacd5ec869bd1947a2cbcd21f62b63 (diff)
Add subfolders creation
Added new not existing subfolders creation in output path to allow CMPv2 integration. Top up version to 1.2.0 Issue-ID: DCAEGEN2-2252 Change-Id: I59f8dfa7fddc5eb3a3fdd80ce18eb3e2272e1bfb Signed-off-by: kjaniak <kornel.janiak@nokia.com>
Diffstat (limited to 'certServiceClient/src/main/java')
-rw-r--r--certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/ArtifactsCreatorProvider.java2
-rw-r--r--certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/conversion/ConvertedArtifactsCreatorFactory.java2
-rw-r--r--certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/writer/CertFileWriter.java16
3 files changed, 17 insertions, 3 deletions
diff --git a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/ArtifactsCreatorProvider.java b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/ArtifactsCreatorProvider.java
index 06a4cc6e..954f3d30 100644
--- a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/ArtifactsCreatorProvider.java
+++ b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/ArtifactsCreatorProvider.java
@@ -40,7 +40,7 @@ public enum ArtifactsCreatorProvider {
PEM("PEM") {
@Override
ArtifactsCreator create(String destPath) {
- return new PemArtifactsCreator(new CertFileWriter(destPath), new PrivateKeyToPemEncoder());
+ return new PemArtifactsCreator(CertFileWriter.createWithDir(destPath), new PrivateKeyToPemEncoder());
}
};
diff --git a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/conversion/ConvertedArtifactsCreatorFactory.java b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/conversion/ConvertedArtifactsCreatorFactory.java
index 586e2952..bda796eb 100644
--- a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/conversion/ConvertedArtifactsCreatorFactory.java
+++ b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/conversion/ConvertedArtifactsCreatorFactory.java
@@ -28,7 +28,7 @@ public class ConvertedArtifactsCreatorFactory {
public static ConvertedArtifactsCreator createConverter(String destPath, String fileExtension, String keyStoreType) {
return new ConvertedArtifactsCreator(
- new CertFileWriter(destPath),
+ CertFileWriter.createWithDir(destPath),
new RandomPasswordGenerator(),
new PemConverter(keyStoreType),
fileExtension);
diff --git a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/writer/CertFileWriter.java b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/writer/CertFileWriter.java
index 2829517c..fec3ebd3 100644
--- a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/writer/CertFileWriter.java
+++ b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/writer/CertFileWriter.java
@@ -23,6 +23,7 @@ import org.onap.aaf.certservice.client.certification.exception.CertFileWriterExc
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Path;
@@ -32,10 +33,15 @@ public class CertFileWriter {
private static final Logger LOGGER = LoggerFactory.getLogger(CertFileWriter.class);
private final String destPath;
- public CertFileWriter(String destPath) {
+ private CertFileWriter(String destPath) {
this.destPath = destPath;
}
+ public static CertFileWriter createWithDir(String destPath) {
+ createDirIfNotExists(destPath);
+ return new CertFileWriter(destPath);
+ }
+
public void saveData(byte[] data, String filename) throws CertFileWriterException {
LOGGER.debug("Attempt to save file {} in path {}", filename, destPath);
try (FileOutputStream outputStream = new FileOutputStream(Path.of(destPath, filename).toString())) {
@@ -45,4 +51,12 @@ public class CertFileWriter {
throw new CertFileWriterException(e);
}
}
+
+ private static void createDirIfNotExists(String destPath) {
+ File destFolderPath = new File(destPath);
+ if (!destFolderPath.exists()) {
+ LOGGER.debug("Destination path not exists, subdirectories are created");
+ destFolderPath.mkdirs();
+ }
+ }
}