Skip to content

Commit

Permalink
Use builder for ShardMetadata
Browse files Browse the repository at this point in the history
Signed-off-by: Andre Kurait <[email protected]>
  • Loading branch information
AndreKurait committed Sep 19, 2024
1 parent 7a72c10 commit e6cd452
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.rfs.version_es_7_10;

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand All @@ -16,9 +16,11 @@

import com.rfs.models.ShardFileInfo;
import com.rfs.models.ShardMetadata;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder(builderClassName = "Builder")
public class ShardMetadataData_ES_7_10 implements ShardMetadata {
private static final ObjectMapper objectMapper = new ObjectMapper();

Expand All @@ -37,34 +39,14 @@ public class ShardMetadataData_ES_7_10 implements ShardMetadata {
private final long totalSizeBytes;
private final List<ShardFileInfo> files;

public ShardMetadataData_ES_7_10(
String snapshotName,
String indexName,
String indexId,
int shardId,
int indexVersion,
long startTime,
long time,
int numberOfFiles,
long totalSize,
List<FileInfoRaw> files
) {
this.snapshotName = snapshotName;
this.indexName = indexName;
this.indexId = indexId;
this.shardId = shardId;
this.indexVersion = indexVersion;
this.startTime = startTime;
this.time = time;
this.numberOfFiles = numberOfFiles;
this.totalSizeBytes = totalSize;

// Convert the raw file metadata to the FileMetadata class
List<FileInfo> convertedFiles = new java.util.ArrayList<>();
for (FileInfoRaw fileMetadataRaw : files) {
convertedFiles.add(FileInfo.fromFileMetadataRaw(fileMetadataRaw));
// Custom builder method to handle rawFiles
public static class Builder {
public Builder rawFiles(List<FileInfoRaw> rawFiles) {
this.files = rawFiles.stream()
.map(FileInfo::fromFileMetadataRaw)
.collect(Collectors.toUnmodifiableList());
return this;
}
this.files = Collections.unmodifiableList(convertedFiles);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ public ShardMetadata fromJsonNode(JsonNode root, String indexId, String indexNam
objectNodeRoot,
ShardMetadataData_ES_7_10.DataRaw.class
);
return new ShardMetadataData_ES_7_10(
shardMetadataRaw.name,
indexName,
indexId,
shardId,
shardMetadataRaw.indexVersion,
shardMetadataRaw.startTime,
shardMetadataRaw.time,
shardMetadataRaw.numberOfFiles,
shardMetadataRaw.totalSize,
shardMetadataRaw.files
);
return ShardMetadataData_ES_7_10.builder()
.snapshotName(shardMetadataRaw.name)
.indexName(indexName)
.indexId(indexId)
.shardId(shardId)
.indexVersion(shardMetadataRaw.indexVersion)
.startTime(shardMetadataRaw.startTime)
.time(shardMetadataRaw.time)
.numberOfFiles(shardMetadataRaw.numberOfFiles)
.totalSizeBytes(shardMetadataRaw.totalSize)
.rawFiles(shardMetadataRaw.files)
.build();
} catch (Exception e) {
throw new ShardMetadata.CouldNotParseShardMetadata(
"Could not parse shard metadata for Index " + indexId + ", Shard " + shardId,
Expand Down

0 comments on commit e6cd452

Please sign in to comment.