-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #872 from Kapral67/issue-871-patch
patch issue 871
- Loading branch information
Showing
34 changed files
with
482 additions
and
362 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
AdminClient/src/main/java/org/familydirectory/sdk/adminclient/enums/flags/Flags.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.familydirectory.sdk.adminclient.enums.flags; | ||
|
||
public | ||
enum Flags { | ||
ISSUE_871 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
AdminClient/src/main/java/org/familydirectory/sdk/adminclient/events/flag/FlagEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package org.familydirectory.sdk.adminclient.events.flag; | ||
|
||
import com.googlecode.lanterna.gui2.WindowBasedTextGUI; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
import java.util.concurrent.CompletableFuture; | ||
import org.familydirectory.assets.ddb.enums.DdbTable; | ||
import org.familydirectory.assets.ddb.enums.member.MemberTableParameter; | ||
import org.familydirectory.assets.ddb.member.Member; | ||
import org.familydirectory.assets.ddb.models.member.MemberRecord; | ||
import org.familydirectory.sdk.adminclient.AdminClientTui; | ||
import org.familydirectory.sdk.adminclient.enums.flags.Flags; | ||
import org.familydirectory.sdk.adminclient.events.model.EventHelper; | ||
import org.familydirectory.sdk.adminclient.utility.SdkClientProvider; | ||
import org.familydirectory.sdk.adminclient.utility.lanterna.WaitingDialog; | ||
import org.jetbrains.annotations.NotNull; | ||
import software.amazon.awssdk.services.dynamodb.DynamoDbClient; | ||
import software.amazon.awssdk.services.dynamodb.model.AttributeValue; | ||
import software.amazon.awssdk.services.dynamodb.model.DeleteItemRequest; | ||
import software.amazon.awssdk.services.dynamodb.model.PutItemRequest; | ||
import software.amazon.awssdk.services.dynamodb.model.ScanRequest; | ||
import software.amazon.awssdk.services.dynamodb.model.ScanResponse; | ||
import static java.util.Collections.emptyMap; | ||
import static java.util.Collections.singletonMap; | ||
import static java.util.Objects.isNull; | ||
import static java.util.Objects.requireNonNull; | ||
import static java.util.Optional.ofNullable; | ||
|
||
public final | ||
class FlagEvent implements EventHelper { | ||
private final @NotNull WindowBasedTextGUI gui; | ||
private final @NotNull Flags flag; | ||
|
||
public | ||
FlagEvent (final @NotNull WindowBasedTextGUI gui, final @NotNull Flags flag) { | ||
super(); | ||
this.gui = requireNonNull(gui); | ||
this.flag = requireNonNull(flag); | ||
} | ||
|
||
@Override | ||
public | ||
void run () { | ||
switch (this.flag) { | ||
case ISSUE_871 -> { | ||
final WaitingDialog waitDialog = WaitingDialog.createDialog(this.flag.name(), "Applying Database Migration, Please Wait"); | ||
waitDialog.setHints(AdminClientTui.EXTRA_WINDOW_HINTS); | ||
waitDialog.showDialog(this.gui, false); | ||
final CompletableFuture<?> future = CompletableFuture.runAsync(() -> { | ||
try { | ||
final SdkClientProvider sdkClientProvider = SdkClientProvider.getSdkClientProvider(); | ||
Map<String, AttributeValue> lastEvaluatedKey = emptyMap(); | ||
do { | ||
final ScanRequest.Builder scanRequestBuilder = ScanRequest.builder() | ||
.tableName(DdbTable.MEMBER.name()) | ||
.consistentRead(true); | ||
if (!lastEvaluatedKey.isEmpty()) { | ||
scanRequestBuilder.exclusiveStartKey(lastEvaluatedKey); | ||
} | ||
|
||
final ScanResponse scanResponse = sdkClientProvider.getSdkClient(DynamoDbClient.class) | ||
.scan(scanRequestBuilder.build()); | ||
for (final Map<String, AttributeValue> entry : scanResponse.items()) { | ||
final UUID id = UUID.fromString(entry.get(MemberTableParameter.ID.jsonFieldName()) | ||
.s()); | ||
|
||
ofNullable(entry.get(MemberTableParameter.ADDRESS.jsonFieldName())).filter(av -> isNull(av.l()) || av.l() | ||
.isEmpty()) | ||
.map(AttributeValue::ss) | ||
.ifPresent(ss -> { | ||
Map<String, AttributeValue> newEntry = new HashMap<>(entry); | ||
|
||
newEntry.remove(MemberTableParameter.ADDRESS.jsonFieldName()); | ||
if (!ss.isEmpty()) { | ||
newEntry.put(MemberTableParameter.ADDRESS.jsonFieldName(), | ||
AttributeValue.fromL(Member.revertAddressDdb(ss))); | ||
} | ||
|
||
// lazy validation | ||
final MemberRecord memberRecord = new MemberRecord(id, Member.convertDdbMap(newEntry), | ||
UUID.fromString(entry.get( | ||
MemberTableParameter.FAMILY_ID.jsonFieldName()) | ||
.s())); | ||
newEntry = Member.retrieveDdbMap(memberRecord); | ||
|
||
sdkClientProvider.getSdkClient(DynamoDbClient.class) | ||
.deleteItem(DeleteItemRequest.builder() | ||
.tableName(DdbTable.MEMBER.name()) | ||
.key(singletonMap( | ||
MemberTableParameter.ID.jsonFieldName(), | ||
AttributeValue.fromS(id.toString()))) | ||
.build()); | ||
sdkClientProvider.getSdkClient(DynamoDbClient.class) | ||
.putItem(PutItemRequest.builder() | ||
.tableName(DdbTable.MEMBER.name()) | ||
.item(newEntry) | ||
.build()); | ||
}); | ||
} | ||
|
||
lastEvaluatedKey = scanResponse.lastEvaluatedKey(); | ||
|
||
} while (!lastEvaluatedKey.isEmpty()); | ||
} finally { | ||
waitDialog.close(); | ||
} | ||
}); | ||
waitDialog.waitUntilClosed(); | ||
try { | ||
future.get(); | ||
} catch (final Throwable e) { | ||
throw new RuntimeException(e); | ||
} | ||
waitDialog.waitUntilClosed(); | ||
} | ||
default -> throw new IllegalStateException("Unhandled Flag: %s".formatted(this.flag.name())); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.