Skip to content

Commit 51cbeab

Browse files
Changes to storage
- Store IssuesSyncStateRecords in GitHubIssuesSyncState (rather than IssuesSyncState) collection - Make the id for IssuesSyncStateRecords a String instead of a ProjectId object - Only run IT_LocalIssueStoreLoader if the pem path is set - Use the real github application id in the application.yaml
1 parent 83557c2 commit 51cbeab

File tree

8 files changed

+16
-13
lines changed

8 files changed

+16
-13
lines changed

src/main/java/edu/stanford/webprotege/issues/handler/LinkedGitHubRepositoryChangedEventHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void handleEvent(LinkedGitHubRepositoryChangedEvent event) {
5050
store.save(linkRecord);
5151
}
5252
else {
53-
store.deleteById(event.projectId());
53+
store.deleteById(event.projectId().id());
5454
}
5555
}
5656
}

src/main/java/edu/stanford/webprotege/issues/persistence/IssuesSyncStateRecord.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
* This record stores information about the link, including the project ID,
2121
* GitHub repository coordinates
2222
*/
23-
@Document(collection = "IssuesSyncState")
23+
@Document(collection = "GitHubIssuesSyncState")
2424
public record IssuesSyncStateRecord(
25-
@Id @JsonProperty("projectId") @Nonnull ProjectId projectId,
25+
@Id @JsonProperty("projectId") @Nonnull String projectId,
2626
@JsonProperty("repoCoords") @Nonnull GitHubRepositoryCoordinates repoCoords,
2727
@JsonProperty("updatedAt") @Nullable Instant updatedAt,
2828
@JsonProperty("syncState") IssuesSyncState syncState) {
@@ -38,7 +38,7 @@ public record IssuesSyncStateRecord(
3838
@JsonCreator
3939
public IssuesSyncStateRecord(
4040
@JsonProperty("projectId")
41-
@Nonnull ProjectId projectId,
41+
@Nonnull String projectId,
4242
@JsonProperty("repoCoords")
4343
@Nonnull GitHubRepositoryCoordinates repoCoords,
4444
@JsonProperty("updatedAt")
@@ -60,7 +60,7 @@ public IssuesSyncStateRecord(
6060
*/
6161
@Nonnull
6262
public static IssuesSyncStateRecord of(@Nonnull ProjectId projectId, @Nonnull GitHubRepositoryCoordinates repoCoords) {
63-
return new IssuesSyncStateRecord(projectId, repoCoords, null, IssuesSyncState.NOT_SYNCED);
63+
return new IssuesSyncStateRecord(projectId.id(), repoCoords, null, IssuesSyncState.NOT_SYNCED);
6464
}
6565

6666
/**

src/main/java/edu/stanford/webprotege/issues/persistence/IssuesSyncStateRecordRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* 2023-10-16
1515
*/
1616
@Repository
17-
public interface IssuesSyncStateRecordRepository extends CrudRepository<IssuesSyncStateRecord, ProjectId> {
17+
public interface IssuesSyncStateRecordRepository extends CrudRepository<IssuesSyncStateRecord, String> {
1818

1919
@Nonnull
2020
List<IssuesSyncStateRecord> findAllByRepoCoords(@Nonnull GitHubRepositoryCoordinates repoCoords);

src/main/java/edu/stanford/webprotege/issues/persistence/LocalIssueStoreManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,21 @@ public LocalIssueStoreManager(IssuesSyncStateRecordRepository syncStateRepo,
3131
}
3232

3333
public synchronized void linkProjectToGitHubRepo(@Nonnull ProjectId projectId, @Nonnull GitHubRepositoryCoordinates repoCoords) {
34-
var existingLink = syncStateRepo.findById(projectId);
34+
var existingLink = syncStateRepo.findById(projectId.id());
3535
if(existingLink.isEmpty()) {
3636
syncStateRepo.save(IssuesSyncStateRecord.of(projectId, repoCoords));
3737
}
3838
}
3939

4040
public synchronized void invalidateLocalIssueStore(@Nonnull ProjectId projectId) {
41-
syncStateRepo.findById(projectId)
41+
syncStateRepo.findById(projectId.id())
4242
.map(record -> record.withSyncState(IssuesSyncState.NOT_SYNCED))
4343
.ifPresent(syncStateRepo::save);
4444
}
4545

4646
public synchronized void ensureLocalStoreIsUpToDate(@Nonnull ProjectId projectId) {
4747
Objects.requireNonNull(projectId);
48-
var record = syncStateRepo.findById(projectId);
48+
var record = syncStateRepo.findById(projectId.id());
4949
record.ifPresentOrElse(r -> {
5050
logger.info("Found linked GitHub repo for {}. Details {}", projectId, r);
5151
},

src/main/java/edu/stanford/webprotege/issues/service/EntityIssuesService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public List<GitHubIssue> getIssues(@Nonnull ProjectId projectId, @Nonnull OWLEnt
7171
localIssueStoreManager.ensureLocalStoreIsUpToDate(projectId);
7272

7373
// Attempt to retrieve the GitHub repository link for the given project
74-
return linkRecordRepository.findById(projectId)
74+
return linkRecordRepository.findById(projectId.id())
7575
.map(IssuesSyncStateRecord::repoCoords)
7676
.map(repoCoord -> {
7777
// Retrieve issues linked directly by IRI

src/test/java/edu/stanford/webprotege/issues/IT_GitHubRepositoryLinkRecordRepository.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void setUp() {
3434
projectId = ProjectId.generate();
3535
repoCoords = GitHubRepositoryCoordinates.of("TestOrg", "TestRepoName");
3636
updatedAt = Instant.now();
37-
repository.save(new IssuesSyncStateRecord(projectId, repoCoords, updatedAt, IssuesSyncState.SYNCED));
37+
repository.save(new IssuesSyncStateRecord(projectId.id(), repoCoords, updatedAt, IssuesSyncState.SYNCED));
3838
}
3939

4040
@AfterEach
@@ -49,7 +49,7 @@ void shouldSaveRecord() {
4949

5050
@Test
5151
void shouldFindByProjectId() {
52-
var found = repository.findById(projectId);
52+
var found = repository.findById(projectId.id());
5353
assertThat(found).isPresent();
5454
}
5555

src/test/java/edu/stanford/webprotege/issues/IT_LocalIssueStoreLoader.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import edu.stanford.webprotege.issues.persistence.LocalIssueStoreLoader;
77
import org.junit.jupiter.api.BeforeEach;
88
import org.junit.jupiter.api.Test;
9+
import org.junit.jupiter.api.condition.EnabledIf;
10+
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
911
import org.junit.jupiter.api.extension.ExtendWith;
1012
import org.springframework.beans.factory.annotation.Autowired;
1113
import org.springframework.boot.test.context.SpringBootTest;
@@ -21,6 +23,7 @@
2123
*/
2224
@SpringBootTest(properties = "webprotege.rabbitmq.commands-subscribe=false")
2325
@ExtendWith(MongoTestExtension.class)
26+
@EnabledIfEnvironmentVariable(named = "WEBPROTEGE_GITHUB_PEM_PATH", matches = ".+", disabledReason = "No path to a PEM file containing a secret key for GitHub has been supplied. Cannot query GitHub without a secret key. Skipping test. To run this test supply a value for the WEBPROTEGE_GITHUB_PEM_PATH environment variable.")
2427
public class IT_LocalIssueStoreLoader {
2528

2629
@Autowired

src/test/resources/application.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ webprotege:
2424
username: admin
2525
password: password
2626
github:
27-
app-id: 123456
27+
app-id: 1628021

0 commit comments

Comments
 (0)