Skip to content

Commit

Permalink
added CreateProjectSmallFilesRequest. (#64)
Browse files Browse the repository at this point in the history
* added CreateProjectSmallFilesRequest.

* fixed shouldCreateProjectFromBackupFile test

---------

Co-authored-by: soimugeo <[email protected]>
  • Loading branch information
soimugeoWB and soimugeo authored Dec 23, 2024
1 parent add05ab commit 15d17c1
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,11 @@ CommandExecutor<PrepareBackupFilesForUseRequest, PrepareBackupFilesForUseRespons
return new CommandExecutorImpl<>(PrepareBackupFilesForUseResponse.class);
}

@Bean
CommandExecutor<CreateProjectSmallFilesRequest, CreateProjectSmallFilesResponse> executorForCreateProjectSmallFiles() {
return new CommandExecutorImpl<>(CreateProjectSmallFilesResponse.class);
}

@Bean
MinioClient minioClient(MinioProperties properties) {
return MinioClient.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@
@Type(SetUserProjectEntityGraphSettingsResult.class),
@Type(UpdateEntityTagsResult.class),
@Type(UpdateFormDescriptorResult.class),
@Type(CreateNewProjectFromProjectBackupResult.class),
})
public interface Result extends Response {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package edu.stanford.protege.webprotege.icd.projects;

import com.fasterxml.jackson.annotation.*;
import edu.stanford.protege.webprotege.common.*;

import static edu.stanford.protege.webprotege.icd.projects.CreateProjectSmallFilesRequest.CHANNEL;

@JsonTypeName(CHANNEL)
public record CreateProjectSmallFilesRequest(
@JsonProperty("projectId") ProjectId projectId
)implements Request<CreateProjectSmallFilesResponse> {
public static final String CHANNEL = "icatx.versioning.CreateProjectSmallFiles";

@Override
public String getChannel() {
return CHANNEL;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package edu.stanford.protege.webprotege.icd.projects;

import com.fasterxml.jackson.annotation.JsonTypeName;
import edu.stanford.protege.webprotege.dispatch.Result;

import static edu.stanford.protege.webprotege.icd.projects.CreateProjectSmallFilesRequest.CHANNEL;

@JsonTypeName(CHANNEL)
public record CreateProjectSmallFilesResponse() implements Result {
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import java.nio.file.Path;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.*;

/**
* Matthew Horridge
Expand All @@ -30,6 +30,8 @@ public class CreateProjectSagaManager {
private final CommandExecutor<CreateInitialRevisionHistoryRequest, CreateInitialRevisionHistoryResponse> createInitialRevisionHistoryExecutor;
private final CommandExecutor<PrepareBackupFilesForUseRequest, PrepareBackupFilesForUseResponse> prepareBinaryFileBackupForUseExecutor;

private final CommandExecutor<CreateProjectSmallFilesRequest, CreateProjectSmallFilesResponse> createProjectSmallFilesExecutor;

private final MinioFileDownloader fileDownloader;

private final RevisionHistoryReplacer revisionHistoryReplacer;
Expand All @@ -41,13 +43,15 @@ public CreateProjectSagaManager(ProjectDetailsManager projectDetailsManager,
CommandExecutor<ProcessUploadedOntologiesRequest, ProcessUploadedOntologiesResponse> processOntologiesExecutor,
CommandExecutor<CreateInitialRevisionHistoryRequest, CreateInitialRevisionHistoryResponse> createInitialRevisionHistoryExecutor,
CommandExecutor<PrepareBackupFilesForUseRequest, PrepareBackupFilesForUseResponse> prepareBinaryFileBackupForUseExecutor,
CommandExecutor<CreateProjectSmallFilesRequest, CreateProjectSmallFilesResponse> createProjectSmallFilesExecutor,
MinioFileDownloader fileDownloader,
RevisionHistoryReplacer revisionHistoryReplacer,
ProjectPermissionsInitializer projectPermissionsInitializer) {
this.projectDetailsManager = projectDetailsManager;
this.processOntologiesExecutor = processOntologiesExecutor;
this.createInitialRevisionHistoryExecutor = createInitialRevisionHistoryExecutor;
this.prepareBinaryFileBackupForUseExecutor = prepareBinaryFileBackupForUseExecutor;
this.createProjectSmallFilesExecutor = createProjectSmallFilesExecutor;
this.revisionHistoryReplacer = revisionHistoryReplacer;
this.fileDownloader = fileDownloader;
this.projectPermissionsInitializer = projectPermissionsInitializer;
Expand Down Expand Up @@ -113,6 +117,7 @@ private CompletableFuture<CreateNewProjectFromProjectBackupResult> createProject
return prepareBackupFilesForRestore(sagaState)
.thenCompose(this::downloadRevisionHistory)
.thenCompose(this::copyRevisionHistoryToProject)
.thenCompose(this::createProjectSmallFiles)
.thenCompose(this::registerProject)
.thenCompose(this::initializeProjectPermissions)
.thenCompose(this::retrieveProjectDetails)
Expand All @@ -129,6 +134,12 @@ private CompletableFuture<CreateNewProjectFromProjectBackupResult> createProject
});
}

private CompletableFuture<SagaStateWithSources> createProjectSmallFiles(SagaStateWithSources sagaState) {
var createHistoryRequest = sagaState.createProjectSmallFiles();
return createProjectSmallFilesExecutor.execute(createHistoryRequest, sagaState.getExecutionContext())
.thenApply(response -> sagaState);
}

private CompletableFuture<SagaStateWithSources> prepareBackupFilesForRestore(SagaStateWithSources sagaState) {
var createHistoryRequest = sagaState.createPrepareBackupFilesForUseRequest();
return prepareBinaryFileBackupForUseExecutor.execute(createHistoryRequest, sagaState.getExecutionContext())
Expand Down Expand Up @@ -269,6 +280,9 @@ public PrepareBackupFilesForUseRequest createPrepareBackupFilesForUseRequest() {
return new PrepareBackupFilesForUseRequest(getProjectId(), getNewProjectSettings().sourceDocument());
}

public CreateProjectSmallFilesRequest createProjectSmallFiles() {
return new CreateProjectSmallFilesRequest(getProjectId());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class CreateProjectSagaManagerTest {

@Mock
private CommandExecutor<PrepareBackupFilesForUseRequest, PrepareBackupFilesForUseResponse> prepareBinaryFileBackupForUseExecutor;
@Mock
private CommandExecutor<CreateProjectSmallFilesRequest, CreateProjectSmallFilesResponse> createProjectSmallFilesExecutor;

@Mock
private MinioFileDownloader fileDownloader;
Expand Down Expand Up @@ -74,6 +76,7 @@ void setUp() {
processOntologiesExecutor,
createInitialRevisionHistoryExecutor,
prepareBinaryFileBackupForUseExecutor,
createProjectSmallFilesExecutor,
fileDownloader,
revisionHistoryReplacer,
projectPermissionsInitializer);
Expand Down Expand Up @@ -238,6 +241,9 @@ void shouldCreateProjectFromBackupFile() throws ExecutionException, InterruptedE
when(projectPermissionsInitializer.applyDefaultPermissions(any(ProjectId.class), any(UserId.class)))
.thenReturn(CompletableFuture.completedFuture(null));

when(createProjectSmallFilesExecutor.execute(any(), eq(executionContext)))
.thenReturn(CompletableFuture.completedFuture(null));

when(projectDetailsManager.getProjectDetails(any(ProjectId.class)))
.thenReturn(projectDetails);

Expand Down

0 comments on commit 15d17c1

Please sign in to comment.