Skip to content

Commit

Permalink
Now FlowFile have parent values. Fixed SourceFile (for real).
Browse files Browse the repository at this point in the history
  • Loading branch information
jgwoolley committed Jan 9, 2025
1 parent cb26a52 commit d7cb5e4
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.yelloowstone.nf2t</groupId>
<artifactId>nf2t-cli</artifactId>
<version>0.0.6-SNAPSHOT</version>
<version>0.0.6</version>

<name>nf2t-cli</name>
<description>A Java CLI for parsing Apache NiFi FlowFiles.</description>
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/com/yelloowstone/nf2t/cli/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
Expand Down Expand Up @@ -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));
Expand All @@ -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()));
}

}
Expand Down Expand Up @@ -173,7 +173,7 @@ public Integer unpackageFlowFileStream(
final Path outputPath = result.getOutputPath();
final List<FlowFileErrorResult> 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);
Expand All @@ -192,7 +192,7 @@ public Integer unpackageFlowFileStream(
if (Files.isDirectory(inputPath)) {
try (final Stream<Path> 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) {
Expand Down Expand Up @@ -239,8 +239,8 @@ public Integer packageFlowFileStream(
Path outputPath = result.getOutputPath();
final List<FlowFileErrorResult> 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
Expand Down Expand Up @@ -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<String, String> attributes = new HashMap<>();
Expand Down
85 changes: 85 additions & 0 deletions src/main/java/com/yelloowstone/nf2t/cli/SourceFile.java
Original file line number Diff line number Diff line change
@@ -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);
}

}
2 changes: 1 addition & 1 deletion update.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mvn versions:set -DnewVersion=0.0.6-SNAPSHOT
mvn versions:set -DnewVersion=0.0.6
mvn versions:commit

0 comments on commit d7cb5e4

Please sign in to comment.