Skip to content

Commit deec2b3

Browse files
Add projectId to output file structure
1 parent d225f6f commit deec2b3

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/main/java/org/radarcns/RestructureAvroRecords.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,18 @@ private void writeRecord(GenericRecord record, String topicName, FileCacheStore
258258
Date time = getDate(keyField, valueField);
259259
java.nio.file.Path outputFileName = createFilename(time);
260260

261+
// Clean Project id for use in final pathname
262+
String projectId = keyField.get("projectId").toString().replaceAll("[^a-zA-Z0-9_-]+", "");
263+
264+
if (projectId == null) {
265+
projectId = "unknown-project";
266+
}
267+
261268
// Clean user id and create final output pathname
262269
String userId = keyField.get("userId").toString().replaceAll("[^a-zA-Z0-9_-]+", "");
263-
java.nio.file.Path userDir = this.outputPath.resolve(userId);
270+
271+
java.nio.file.Path projectDir = this.outputPath.resolve(projectId);
272+
java.nio.file.Path userDir = projectDir.resolve(userId);
264273
java.nio.file.Path userTopicDir = userDir.resolve(topicName);
265274
java.nio.file.Path outputPath = userTopicDir.resolve(outputFileName);
266275

0 commit comments

Comments
 (0)