diff --git a/pom.xml b/pom.xml index 30f6077..67e6077 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.yelloowstone.nf2t nf2t-cli - 0.0.6-SNAPSHOT + 0.0.6 nf2t-cli A Java CLI for parsing Apache NiFi FlowFiles. diff --git a/src/main/java/com/yelloowstone/nf2t/cli/App.java b/src/main/java/com/yelloowstone/nf2t/cli/App.java index 62fc892..3565476 100644 --- a/src/main/java/com/yelloowstone/nf2t/cli/App.java +++ b/src/main/java/com/yelloowstone/nf2t/cli/App.java @@ -79,7 +79,7 @@ private void unpackageFlowFileInputStream(final FlowFileStreamResult result, fin if (filename != null) { Path newContentPath = contentPath.getParent().resolve(filename); Files.move(contentPath, newContentPath); - flowFileResult.setContentPath(new SourceFile(newContentPath.toAbsolutePath().toString(), + flowFileResult.setContentPath(new SourceFile(null, newContentPath.toAbsolutePath().toString(), newContentPath.getFileName().getFileName().toString(), flowFileResult.getContentSize())); } @@ -107,7 +107,7 @@ private void unpackageInputStream(final FlowFileStreamResult result, final Input while ((entry = zipIs.getNextEntry()) != null) { final String newAbsolutePath = entry.getName(); final String newFilename = new File(entry.getName()).getName(); - unpackageInputStream(result, zipIs, new SourceFile(newAbsolutePath, newFilename, entry.getSize())); + unpackageInputStream(result, zipIs, new SourceFile(source, newAbsolutePath, newFilename, entry.getSize())); } } catch (Exception e) { errors.add(new FlowFileErrorResult(e, source)); @@ -128,7 +128,7 @@ private void unpackageInputStream(final FlowFileStreamResult result, final Input } else { final String newAbsolutePath = entry.getName(); final String newFilename = new File(entry.getName()).getName(); - unpackageInputStream(result, tarInputStream, new SourceFile(newAbsolutePath, newFilename, entry.getSize())); + unpackageInputStream(result, tarInputStream, new SourceFile(source, newAbsolutePath, newFilename, entry.getSize())); } } @@ -173,7 +173,7 @@ public Integer unpackageFlowFileStream( final Path outputPath = result.getOutputPath(); final List errors = result.getErrors(); - final SourceFile source = SourceFile.fromPath(inputPath); + final SourceFile source = SourceFile.fromPath(null, inputPath); // Get Packager For Current Version final FlowFilePackageVersion packageVersion = packageVersions.get(version); @@ -192,7 +192,7 @@ public Integer unpackageFlowFileStream( if (Files.isDirectory(inputPath)) { try (final Stream files = Files.list(inputPath)) { files.forEach(x -> { - final SourceFile newSource = SourceFile.fromPath(x); + final SourceFile newSource = SourceFile.fromPath(null, x); try(final InputStream is = Files.newInputStream(x)) { unpackageInputStream(result, is, newSource); } catch (IOException e) { @@ -239,8 +239,8 @@ public Integer packageFlowFileStream( Path outputPath = result.getOutputPath(); final List errors = result.getErrors(); - final SourceFile source = SourceFile.fromPath(inputPath); - final SourceFile output = SourceFile.fromPath(outputPath); + final SourceFile source = SourceFile.fromPath(null, inputPath); + final SourceFile output = SourceFile.fromPath(null, outputPath); // Get Packager For Current Version @@ -280,7 +280,7 @@ public Integer packageFlowFileStream( try (OutputStream outputStream = Files.newOutputStream(outputPath)) { for (Path contentPath : contentPaths) { - final SourceFile content = SourceFile.fromPath(outputPath); + final SourceFile content = SourceFile.fromPath(null, outputPath); try { final Map attributes = new HashMap<>(); diff --git a/src/main/java/com/yelloowstone/nf2t/cli/SourceFile.java b/src/main/java/com/yelloowstone/nf2t/cli/SourceFile.java new file mode 100644 index 0000000..a8723e9 --- /dev/null +++ b/src/main/java/com/yelloowstone/nf2t/cli/SourceFile.java @@ -0,0 +1,85 @@ +package com.yelloowstone.nf2t.cli; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.UUID; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class SourceFile { + @JsonProperty("parent") + private final SourceFile parent; + + @JsonProperty("absolutePath") + private final String absolutePath; + + @JsonProperty("filename") + private final String filename; + + @JsonProperty("size") + private final long size; + + @JsonProperty("uuid") + private final UUID uuid; + @JsonCreator + public SourceFile(@JsonProperty("parent") SourceFile parent, @JsonProperty("absolutePath") String absolutePath, @JsonProperty("filename") String filename, @JsonProperty("size") long size, @JsonProperty("uuid") UUID uuid) { + this.parent = parent; + this.absolutePath = absolutePath; + this.filename = filename; + this.size = size; + this.uuid = uuid; + } + + public SourceFile(SourceFile parent, String absolutePath, String filename, long size) { + this(parent, absolutePath, filename, size, UUID.randomUUID()); + } + + /** + * @see org.apache.nifi.flowfile.attributes.CoreAttributes#ABSOLUTE_PATH + * + * @return + */ + public String getAbsolutePath() { + return absolutePath; + } + + /** + * @see org.apache.nifi.flowfile.attributes.CoreAttributes#FILENAME + * + * @return + */ + public String getFilename() { + return filename; + } + + public long getSize() { + return size; + } + + /** + * @see org.apache.nifi.flowfile.attributes.CoreAttributes#UUID + * + * @return + */ + public UUID getUuid() { + return uuid; + } + + + public static SourceFile fromPath(SourceFile parent, Path inputPath) { + final String absolutePath = inputPath.toAbsolutePath().toString(); + final String filename = inputPath.getFileName().toString(); + long size = -1; + + try { + size = Files.size(inputPath); + } catch (IOException e) { + + } + + return new SourceFile(parent, absolutePath, filename, size); + } + +} diff --git a/update.sh b/update.sh index a214826..1cd6c8f 100644 --- a/update.sh +++ b/update.sh @@ -1,2 +1,2 @@ -mvn versions:set -DnewVersion=0.0.6-SNAPSHOT +mvn versions:set -DnewVersion=0.0.6 mvn versions:commit