-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(index): support subjects in index commits
They are either part of the current commit or supplied via the staging area context. Denote resource and version documents as commit subjects.
- Loading branch information
Showing
8 changed files
with
184 additions
and
10 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
77 changes: 77 additions & 0 deletions
77
...ational.index.tests/src/com/b2international/index/revision/RevisionCommitSubjectTest.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,77 @@ | ||
/* | ||
* Copyright 2023 B2i Healthcare Pte Ltd, https://b2i.sg | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.b2international.index.revision; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import org.junit.Test; | ||
|
||
import com.b2international.index.Doc; | ||
|
||
/** | ||
* @since 9.0 | ||
*/ | ||
public class RevisionCommitSubjectTest extends BaseRevisionIndexTest { | ||
|
||
@Doc | ||
private static final class SubjectRevision extends Revision implements CommitSubject { | ||
|
||
public SubjectRevision(String id) { | ||
super(id); | ||
} | ||
|
||
@Override | ||
public String extractSubjectId() { | ||
return getId(); | ||
} | ||
|
||
} | ||
|
||
private static final class CommitSubjectSupplierImpl implements CommitSubjectSupplier { | ||
|
||
@Override | ||
public Set<String> getSubjectIds() { | ||
return Set.of(STORAGE_KEY2); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
protected Collection<Class<?>> getTypes() { | ||
return List.of(SubjectRevision.class, RevisionFixtures.RevisionData.class); | ||
} | ||
|
||
@Test | ||
public void commitSubject() throws Exception { | ||
Commit commit = indexRevision(MAIN, new SubjectRevision(STORAGE_KEY1)); | ||
assertThat(commit.getSubjects()).containsOnly(STORAGE_KEY1); | ||
} | ||
|
||
@Test | ||
public void commitSubjectSupplier() throws Exception { | ||
Commit commit = index().prepareCommit(MAIN) | ||
.withContext(new CommitSubjectSupplierImpl()) | ||
.stageNew(new RevisionFixtures.RevisionData(STORAGE_KEY1, "field1", "field2")) | ||
.commit(currentTime(), USER_ID, "Commit"); | ||
|
||
assertThat(commit.getSubjects()).containsOnly(STORAGE_KEY2); | ||
} | ||
|
||
} |
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
27 changes: 27 additions & 0 deletions
27
commons/com.b2international.index/src/com/b2international/index/revision/CommitSubject.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,27 @@ | ||
/* | ||
* Copyright 2023 B2i Healthcare Pte Ltd, https://b2i.sg | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.b2international.index.revision; | ||
|
||
/** | ||
* Simple marker interface to denote a revision document as a subject of a commit and extract a unique identifier to identify the subject when extracting a {@link Commit}. | ||
* | ||
* @since 9.0 | ||
*/ | ||
public interface CommitSubject { | ||
|
||
String extractSubjectId(); | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
...m.b2international.index/src/com/b2international/index/revision/CommitSubjectSupplier.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,27 @@ | ||
/* | ||
* Copyright 2023 B2i Healthcare Pte Ltd, https://b2i.sg | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.b2international.index.revision; | ||
|
||
import java.util.Set; | ||
|
||
/** | ||
* Interface to use for {@link StagingArea} context objects when they'd like to populate external information in the {@link Commit} document's subjects array. | ||
*/ | ||
public interface CommitSubjectSupplier { | ||
|
||
Set<String> getSubjectIds(); | ||
|
||
} |
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