Skip to content

Commit f963c28

Browse files
authored
refactor: added getAuditReader to TransactionalTargetSystem (#738)
1 parent 772366d commit f963c28

File tree

10 files changed

+108
-38
lines changed

10 files changed

+108
-38
lines changed

cli/flamingock-cli/src/main/java/io/flamingock/cli/service/AuditService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public Optional<AuditEntryIssue> getAuditEntryIssue(String changeId) {
109109
if (changeId == null || changeId.trim().isEmpty()) {
110110
throw new IllegalArgumentException("Change ID is required");
111111
}
112-
return opsClient.getAuditIssueByChange(changeId.trim());
112+
return opsClient.getAuditIssueByChangeId(changeId.trim());
113113
}
114114

115115
private OpsClient createOpsClient() {

cloud/flamingock-cloud/src/main/java/io/flamingock/cloud/CloudAuditPersistenceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public List<AuditEntry> getAuditHistory() {
9494
}
9595

9696
@Override
97-
public List<AuditEntry> getSnapshotList() {
97+
public List<AuditEntry> getAuditSnapshot() {
9898
throw new UnsupportedOperationException("getSnapshotList still not implemented for cloud edition");
9999
}
100100

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package io.flamingock.internal.core.builder.ops;
17-
18-
import io.flamingock.internal.common.core.audit.AuditEntry;
16+
package io.flamingock.internal.common.core.audit;
1917

2018
import java.util.List;
2119

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,27 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package io.flamingock.internal.core.builder.ops;
16+
package io.flamingock.internal.common.core.audit;
1717

1818
import io.flamingock.internal.common.core.audit.issue.AuditEntryIssue;
19-
import io.flamingock.internal.common.core.recovery.FixResult;
20-
import io.flamingock.internal.common.core.recovery.Resolution;
2119

2220
import java.util.List;
2321
import java.util.Optional;
2422

25-
public interface AuditIssueManager {
26-
/**
27-
* Get detailed information about a specific change that has issues.
28-
* This includes full audit history, error messages, and execution attempts.
29-
*
30-
* @param changeId the change ID to inspect
31-
* @return detailed issue information including all audit entries, error details, etc.
32-
*/
33-
Optional<AuditEntryIssue> getAuditIssueByChange(String changeId);
34-
23+
public interface AuditIssueReader {
3524
/**
3625
* Get only entries with issues
3726
* @return List of audit entries with problems/issues
3827
*/
3928
List<AuditEntryIssue> getAuditIssues();
4029

4130
/**
42-
* Resolves an audit issue for the given change by marking it as
43-
* either {@link Resolution#APPLIED} or {@link Resolution#ROLLED_BACK}.
31+
* Get detailed information about a specific change that has issues.
32+
* This includes full audit history, error messages, and execution attempts.
4433
*
45-
* @param changeId the change identifier
46-
* @param resolution how the issue should be resolved
47-
* @return result of the fix operation
34+
* @param changeId the change ID to inspect
35+
* @return detailed issue information including all audit entries, error details, etc.
4836
*/
49-
FixResult fixAuditIssue(String changeId, Resolution resolution);
37+
Optional<AuditEntryIssue> getAuditIssueByChangeId(String changeId);
38+
5039
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2025 Flamingock (https://www.flamingock.io)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.flamingock.internal.common.core.audit;
17+
18+
import io.flamingock.internal.common.core.recovery.FixResult;
19+
import io.flamingock.internal.common.core.recovery.Resolution;
20+
21+
public interface AuditIssueResolver extends AuditIssueReader {
22+
23+
24+
/**
25+
* Resolves an audit issue for the given change by marking it as
26+
* either {@link Resolution#APPLIED} or {@link Resolution#ROLLED_BACK}.
27+
*
28+
* @param changeId the change identifier
29+
* @param resolution how the issue should be resolved
30+
* @return result of the fix operation
31+
*/
32+
FixResult fixAuditIssue(String changeId, Resolution resolution);
33+
}

core/flamingock-core-commons/src/main/java/io/flamingock/internal/common/core/audit/AuditReader.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,20 @@
1919
import io.flamingock.internal.common.core.audit.issue.AuditEntryIssueFactory;
2020
import io.flamingock.internal.common.core.audit.issue.NonIssue;
2121

22-
import java.util.Collections;
2322
import java.util.List;
2423
import java.util.Optional;
2524
import java.util.stream.Collectors;
2625

27-
public interface AuditReader {
26+
public interface AuditReader extends AuditHistoryReader, AuditIssueReader {
2827

29-
List<AuditEntry> getAuditHistory();
30-
31-
default List<AuditEntry> getSnapshotList() {
28+
default List<AuditEntry> getAuditSnapshot() {
3229
AuditSnapshotBuilder builder = new AuditSnapshotBuilder();
3330
getAuditHistory().forEach(builder::addEntry);
3431
return builder.buildList();
3532
}
3633

3734
default List<AuditEntryIssue> getAuditIssues() {
38-
return getSnapshotList()
35+
return getAuditSnapshot()
3936
.stream()
4037
.map(AuditEntryIssueFactory::getIssue)
4138
.filter(issue -> !(issue instanceof NonIssue))
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright 2025 Flamingock (https://www.flamingock.io)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.flamingock.internal.common.core.audit;
17+
18+
public enum AuditReaderType {
19+
MONGOCK
20+
}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package io.flamingock.internal.core.builder.ops;
17-
18-
import io.flamingock.internal.common.core.audit.AuditEntry;
16+
package io.flamingock.internal.common.core.audit;
1917

2018
import java.time.LocalDateTime;
2119
import java.util.List;

core/flamingock-core/src/main/java/io/flamingock/internal/core/builder/ops/OpsClient.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
package io.flamingock.internal.core.builder.ops;
1717

1818
import io.flamingock.internal.common.core.audit.AuditEntry;
19+
import io.flamingock.internal.common.core.audit.AuditHistoryReader;
20+
import io.flamingock.internal.common.core.audit.AuditIssueResolver;
21+
import io.flamingock.internal.common.core.audit.AuditSnapshotReader;
1922
import io.flamingock.internal.common.core.audit.issue.AuditEntryIssue;
2023
import io.flamingock.internal.common.core.recovery.FixResult;
2124
import io.flamingock.internal.common.core.recovery.Resolution;
@@ -31,7 +34,7 @@
3134
import java.util.Optional;
3235
import java.util.stream.Collectors;
3336

34-
public class OpsClient implements AuditSnapshotReader, AuditHistoryReader, AuditIssueManager {
37+
public class OpsClient implements AuditSnapshotReader, AuditHistoryReader, AuditIssueResolver {
3538
private final Logger logger = FlamingockLoggerFactory.getLogger("OpsClient");
3639

3740
private final AuditPersistence auditPersistence;
@@ -48,20 +51,20 @@ public List<AuditEntry> getAuditHistory() {
4851
@Override
4952
public List<AuditEntry> getAuditSnapshot() {
5053
logger.debug("Getting audit entries snapshot (latest per change)");
51-
return auditPersistence.getSnapshotList();
54+
return auditPersistence.getAuditSnapshot();
5255
}
5356

5457
@Override
5558
public List<AuditEntry> getAuditSnapshotSince(LocalDateTime since) {
5659
logger.debug("Getting audit entries since: {}", since);
57-
return auditPersistence.getSnapshotList()
60+
return auditPersistence.getAuditSnapshot()
5861
.stream()
5962
.filter(auditEntry -> !auditEntry.getCreatedAt().isBefore(since))
6063
.collect(Collectors.toList());
6164
}
6265

6366
@Override
64-
public Optional<AuditEntryIssue> getAuditIssueByChange(String changeId) {
67+
public Optional<AuditEntryIssue> getAuditIssueByChangeId(String changeId) {
6568
logger.debug("Getting issue details for changeId: {}", changeId);
6669
return auditPersistence.getAuditIssueByChangeId(changeId);
6770
}
@@ -77,7 +80,7 @@ public List<AuditEntryIssue> getAuditIssues() {
7780
public FixResult fixAuditIssue(String changeId, Resolution resolution) {
7881
logger.debug("Change[{}] marked as {}", changeId, resolution);
7982

80-
Optional<AuditEntryIssue> auditIssue = getAuditIssueByChange(changeId);
83+
Optional<AuditEntryIssue> auditIssue = getAuditIssueByChangeId(changeId);
8184
if (!auditIssue.isPresent()) {
8285
return FixResult.NO_ISSUE_FOUND;
8386
}

core/flamingock-core/src/main/java/io/flamingock/internal/core/targets/TransactionalTargetSystem.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@
1515
*/
1616
package io.flamingock.internal.core.targets;
1717

18+
import io.flamingock.internal.common.core.audit.AuditHistoryReader;
19+
import io.flamingock.internal.common.core.audit.AuditReaderType;
1820
import io.flamingock.internal.common.core.context.ContextInitializable;
1921
import io.flamingock.internal.core.runtime.ExecutionRuntime;
2022
import io.flamingock.internal.core.targets.mark.NoOpTargetSystemAuditMarker;
2123
import io.flamingock.internal.core.targets.mark.TargetSystemAuditMarker;
2224
import io.flamingock.internal.core.transaction.TransactionWrapper;
2325
import io.flamingock.internal.util.constants.CommunityPersistenceConstants;
2426

27+
import java.util.Optional;
2528
import java.util.function.Function;
2629

2730
/**
@@ -98,4 +101,33 @@ public TargetSystemAuditMarker getOnGoingTaskStatusRepository() {
98101
*/
99102
abstract public TransactionWrapper getTxWrapper();
100103

104+
/**
105+
* Returns an audit history reader for importing audit entries from external migration sources.
106+
* <p>
107+
* This method enables Flamingock to import audit history from legacy migration tools or other
108+
* Flamingock installations, preventing re-execution of already-applied changes. The returned
109+
* reader provides access to historical audit entries that can be written to Flamingock's audit store.
110+
* <p>
111+
* Common use cases include:
112+
* <ul>
113+
* <li><strong>Mongock migration</strong>: Import Mongock change history when migrating from Mongock to Flamingock</li>
114+
* <li><strong>Community to Cloud migration</strong>: Import audit history from local database to Flamingock Cloud backend</li>
115+
* <li><strong>Future extensibility</strong>: Support for other migration tools (Liquibase, Flyway, etc.)</li>
116+
* </ul>
117+
* <p>
118+
* The default implementation returns {@code Optional.empty()}, indicating no audit reader is available.
119+
* Target system implementations should override this method to provide database-specific readers when
120+
* migration support is needed.
121+
*
122+
* @param type the type of audit reader to retrieve (e.g., {@link AuditReaderType#MONGOCK})
123+
* @return an {@link Optional} containing the audit history reader if supported for the given type,
124+
* or {@link Optional#empty()} if this target system does not support audit reading for the specified type
125+
* @see AuditHistoryReader
126+
* @see AuditReaderType
127+
* @see io.flamingock.importer.ImporterAdapter
128+
*/
129+
public Optional<AuditHistoryReader> getAuditAuditReader(AuditReaderType type) {
130+
return Optional.empty();
131+
}
132+
101133
}

0 commit comments

Comments
 (0)