Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create new project from project backup #63

Merged
merged 8 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
<dependency>
<groupId>edu.stanford.protege</groupId>
<artifactId>webprotege-ipc</artifactId>
<version>1.0.9</version>
<version>1.0.10</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import edu.stanford.protege.webprotege.hierarchy.NamedHierarchyManager;
import edu.stanford.protege.webprotege.hierarchy.NamedHierarchyManagerImpl;
import edu.stanford.protege.webprotege.hierarchy.NamedHierarchyRepository;
import edu.stanford.protege.webprotege.icd.projects.*;
import edu.stanford.protege.webprotege.index.*;
import edu.stanford.protege.webprotege.inject.*;
import edu.stanford.protege.webprotege.inject.project.ProjectDirectoryFactory;
Expand Down Expand Up @@ -189,12 +190,8 @@ OWLDataFactory getOwlDataFactory() {
}

@Bean
ProjectDirectoryFactory getProjectDirectoryFactory() {
return new ProjectDirectoryFactory(getDataDirectory());
}

private File getDataDirectory() {
return null;
ProjectDirectoryFactory getProjectDirectoryFactory(DataDirectoryProvider dataDirectoryProvider) {
return new ProjectDirectoryFactory(dataDirectoryProvider.get());
}

@Bean
Expand Down Expand Up @@ -575,6 +572,11 @@ CommandExecutor<CreateInitialRevisionHistoryRequest, CreateInitialRevisionHistor
return new CommandExecutorImpl<>(CreateInitialRevisionHistoryResponse.class);
}

@Bean
CommandExecutor<PrepareBackupFilesForUseRequest, PrepareBackupFilesForUseResponse> executorForPrepareBackupFilesForUse() {
return new CommandExecutorImpl<>(PrepareBackupFilesForUseResponse.class);
}

@Bean
MinioClient minioClient(MinioProperties properties) {
return MinioClient.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import edu.stanford.protege.webprotege.icd.hierarchy.ClassHierarchyRetiredClassDetector;
import edu.stanford.protege.webprotege.index.*;
import edu.stanford.protege.webprotege.individuals.*;
import edu.stanford.protege.webprotege.inject.ProjectBackupDirectoryProvider;
import edu.stanford.protege.webprotege.inject.project.ProjectDirectoryProvider;
import edu.stanford.protege.webprotege.ipc.EventDispatcher;
import edu.stanford.protege.webprotege.issues.*;
import edu.stanford.protege.webprotege.lang.*;
Expand Down Expand Up @@ -741,6 +743,18 @@ GetProjectInfoActionHandler getProjectInfoActionHandler(AccessManager p1,
return new GetProjectInfoActionHandler(p1, p2, p3);
}

@Bean
public ProjectBackupManager getProjectBackupManager(ProjectDirectoryProvider p1,
ProjectBackupDirectoryProvider p2) {
return new ProjectBackupManager(p1, p2);
}

@Bean
CreateBackupOwlFileActionHandler createBackupOwlFileActionHandler(AccessManager p1,
ProjectBackupManager p2) {
return new CreateBackupOwlFileActionHandler(p1, p2);
}


@Bean
GetHierarchySiblingsActionHandler getHierarchySiblingsActionHandler(AccessManager p1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1166,14 +1166,18 @@ ClassFrameProviderImpl classFrameProvider(Class2ClassFrameTranslatorFactory p1)
return new ClassFrameProviderImpl(p1);
}

@Bean
ProjectBackupDirectoryProvider projectBackupDirectoryProvider(ProjectId projectId){
return new ProjectBackupDirectoryProvider(projectId);
}

@Bean
@LuceneIndexesDirectory
Path luceneIndexesDirectory(DataDirectoryProvider dataDirectoryProvider) {
var dataDirectory = dataDirectoryProvider.get().toPath();
return dataDirectory.resolve("lucene-indexes");

}

@Bean
ActiveLanguagesManagerImpl activeLanguagesManager(ProjectId p1,
AxiomsByEntityReferenceIndex p2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public OntologyChangeList<Set<E>> generateChanges(ChangeGenerationContext contex
OWLAnnotationProperty titleProperty = dataFactory.getOWLAnnotationProperty(propertyIRITitle);

OWLLiteral literal = dataFactory.getOWLLiteral(sourceText, langTag);
OWLNamedIndividual titleIndividual = dataFactory.getOWLNamedIndividual(IRI.create(IcdConstants.NS, "TitleTerm_"+sourceText.replace(" ","_")));
OWLNamedIndividual titleIndividual = dataFactory.getOWLNamedIndividual(IRI.create(IcdConstants.NS, "TitleTerm_"+UUID.randomUUID()));

OWLAnnotationAssertionAxiom titleAxiom = dataFactory.getOWLAnnotationAssertionAxiom(titleProperty, freshEntity.getIRI(), titleIndividual.getIRI());
OWLAnnotationAssertionAxiom newLabelAxiom = dataFactory.getOWLAnnotationAssertionAxiom(labelProperty, titleIndividual.getIRI(), literal);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package edu.stanford.protege.webprotege.icd.exceptions;

public class FileActionException extends RuntimeException {
public FileActionException(String message, Throwable exception) {
super(message, exception);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package edu.stanford.protege.webprotege.icd.projects;

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

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

@JsonTypeName(CHANNEL)
public record PrepareBackupFilesForUseRequest(
@JsonProperty("projectId") ProjectId projectId,
@JsonProperty("fileSubmissionId") DocumentId fileSubmissionId
) implements Request<PrepareBackupFilesForUseResponse> {

public static final String CHANNEL = "icatx.versioning.PrepareBinaryFileBackupForUse";

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

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

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

@JsonTypeName(CHANNEL)
public record PrepareBackupFilesForUseResponse(
@JsonProperty("binaryFileLocation") BlobLocation binaryFileLocation
) implements Result {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package edu.stanford.protege.webprotege.inject;

import edu.stanford.protege.webprotege.common.ProjectId;
import org.springframework.beans.factory.annotation.Value;

import javax.inject.Provider;
import java.io.File;
import java.nio.file.Path;

public class ProjectBackupDirectoryProvider implements Provider<File> {

@Value("${webprotege.directories.backup}")
private Path backupDirectory;

private ProjectId projectId;

public ProjectBackupDirectoryProvider(ProjectId projectId) {
this.projectId = projectId;
}


@Override
public File get() {
return new File(backupDirectory.toFile(), projectId.id());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package edu.stanford.protege.webprotege.project;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import edu.stanford.protege.webprotege.common.ProjectId;
import edu.stanford.protege.webprotege.dispatch.ProjectAction;

import javax.annotation.Nonnull;

import static edu.stanford.protege.webprotege.project.CreateBackupOwlFileAction.CHANNEL;

@JsonTypeName(CHANNEL)

public record CreateBackupOwlFileAction(@JsonProperty("projectId") ProjectId projectId) implements ProjectAction<CreateBackupOwlFileResponse>, HasProjectId {
public final static String CHANNEL = "webprotege.projects.CreateBackupOwlFile";

@Override
public String getChannel() {
return CHANNEL;
}
@Nonnull
@Override
public ProjectId projectId() {
return projectId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package edu.stanford.protege.webprotege.project;

import edu.stanford.protege.webprotege.access.AccessManager;
import edu.stanford.protege.webprotege.dispatch.AbstractProjectActionHandler;
import edu.stanford.protege.webprotege.ipc.ExecutionContext;
import org.jetbrains.annotations.NotNull;

import java.nio.file.Path;

public class CreateBackupOwlFileActionHandler extends AbstractProjectActionHandler<CreateBackupOwlFileAction, CreateBackupOwlFileResponse> {

private final ProjectBackupManager projectBackupManager;

public CreateBackupOwlFileActionHandler(@NotNull AccessManager accessManager, ProjectBackupManager projectBackupManager) {
super(accessManager);
this.projectBackupManager = projectBackupManager;
}

@NotNull
@Override
public Class<CreateBackupOwlFileAction> getActionClass() {
return CreateBackupOwlFileAction.class;
}


@NotNull
@Override
public CreateBackupOwlFileResponse execute(@NotNull CreateBackupOwlFileAction action, @NotNull ExecutionContext executionContext) {
Path owlBackupFile = projectBackupManager.createBackup();
return new CreateBackupOwlFileResponse(owlBackupFile.toString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package edu.stanford.protege.webprotege.project;

import edu.stanford.protege.webprotege.api.ActionExecutor;
import edu.stanford.protege.webprotege.ipc.CommandHandler;
import edu.stanford.protege.webprotege.ipc.ExecutionContext;
import edu.stanford.protege.webprotege.ipc.WebProtegeHandler;
import org.jetbrains.annotations.NotNull;
import reactor.core.publisher.Mono;

@WebProtegeHandler
public class CreateBackupOwlFileCommandHandler implements CommandHandler<CreateBackupOwlFileAction, CreateBackupOwlFileResponse> {
private final ActionExecutor executor;

public CreateBackupOwlFileCommandHandler(ActionExecutor executor) {
this.executor = executor;
}

@NotNull
@Override
public String getChannelName() {
return CreateBackupOwlFileAction.CHANNEL;
}

@Override
public Class<CreateBackupOwlFileAction> getRequestClass() {
return CreateBackupOwlFileAction.class;
}

@Override
public Mono<CreateBackupOwlFileResponse> handleRequest(CreateBackupOwlFileAction request, ExecutionContext executionContext) {
var result = executor.execute(request, new ExecutionContext(executionContext.userId(), executionContext.jwt()));
return Mono.just(result);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package edu.stanford.protege.webprotege.project;

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

import static edu.stanford.protege.webprotege.project.CreateBackupOwlFileAction.CHANNEL;

@JsonTypeName(CHANNEL)
public record CreateBackupOwlFileResponse(@JsonProperty("owlFileBackupLocation") String owlFileBackupLocation) implements Result, Response {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package edu.stanford.protege.webprotege.project;

import com.fasterxml.jackson.annotation.*;
import com.google.common.base.Objects;
import edu.stanford.protege.webprotege.common.ProjectId;
import edu.stanford.protege.webprotege.dispatch.Action;

import static com.google.common.base.MoreObjects.toStringHelper;

@JsonTypeName(CreateNewProjectFromProjectBackupAction.CHANNEL)
public record CreateNewProjectFromProjectBackupAction(
@JsonProperty("newProjectId") ProjectId newProjectId,
@JsonProperty("newProjectSettings") NewProjectSettings newProjectSettings
) implements Action<CreateNewProjectFromProjectBackupResult> {

public static final String CHANNEL = "webprotege.projects.CreateNewProjectFromProjectBackup";

@Override
public String getChannel() {
return CHANNEL;
}

@Override
public int hashCode() {
return Objects.hashCode(newProjectId, newProjectSettings);
}

@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof CreateNewProjectFromProjectBackupAction other)) {
return false;
}
return this.newProjectId.equals(other.newProjectId) && this.newProjectSettings.equals(other.newProjectSettings);
}

@Override
public String toString() {
return toStringHelper("CreateNewProjectFromProjectBackupAction")
.addValue(newProjectId)
.addValue(newProjectSettings)
.toString();
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package edu.stanford.protege.webprotege.project;

import edu.stanford.protege.webprotege.authorization.*;
import edu.stanford.protege.webprotege.ipc.*;
import reactor.core.publisher.Mono;

import javax.annotation.Nonnull;
import java.util.*;

import static edu.stanford.protege.webprotege.access.BuiltInAction.*;


@WebProtegeHandler
public class CreateNewProjectFromProjectBackupCommandHandler implements AuthorizedCommandHandler<CreateNewProjectFromProjectBackupAction, CreateNewProjectFromProjectBackupResult> {


private final CreateProjectSagaManager createProjectSagaManager;


public CreateNewProjectFromProjectBackupCommandHandler(CreateProjectSagaManager createProjectSagaManager) {
this.createProjectSagaManager = createProjectSagaManager;
}

@Nonnull
@Override
public String getChannelName() {
return CreateNewProjectFromProjectBackupAction.CHANNEL;
}

@Override
public Class<CreateNewProjectFromProjectBackupAction> getRequestClass() {
return CreateNewProjectFromProjectBackupAction.class;
}

@Override
public Mono<CreateNewProjectFromProjectBackupResult> handleRequest(CreateNewProjectFromProjectBackupAction request,
ExecutionContext executionContext) {
var result = createProjectSagaManager.executeFromBackup(request.newProjectSettings(), executionContext);
return Mono.fromFuture(result);
}

@Nonnull
@Override
public Resource getTargetResource(CreateNewProjectFromProjectBackupAction request) {
return ApplicationResource.get();
}

@Nonnull
@Override
public Collection<ActionId> getRequiredCapabilities() {
return List.of(CREATE_EMPTY_PROJECT.getActionId(), UPLOAD_PROJECT.getActionId());
}


}
Loading
Loading