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

added dropdown for source type for creating project from sources #89

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
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@

import com.google.web.bindery.event.shared.EventBus;
import edu.stanford.bmir.protege.web.client.app.ApplicationEnvironmentManager;
import edu.stanford.bmir.protege.web.client.dispatch.DispatchErrorMessageDisplay;
import edu.stanford.bmir.protege.web.client.dispatch.DispatchServiceCallbackWithProgressDisplay;
import edu.stanford.bmir.protege.web.client.dispatch.DispatchServiceManager;
import edu.stanford.bmir.protege.web.client.dispatch.ProgressDisplay;
import edu.stanford.bmir.protege.web.client.dispatch.*;
import edu.stanford.bmir.protege.web.client.library.msgbox.MessageBox;
import edu.stanford.bmir.protege.web.client.projectmanager.ProjectCreatedEvent;
import edu.stanford.bmir.protege.web.client.upload.FileUploader;
import edu.stanford.bmir.protege.web.client.user.LoggedInUserManager;
import edu.stanford.bmir.protege.web.client.uuid.UuidV4;
import edu.stanford.bmir.protege.web.shared.csv.DocumentId;
import edu.stanford.bmir.protege.web.shared.dispatch.actions.GetUserInfoAction;
import edu.stanford.bmir.protege.web.shared.dispatch.actions.GetUserInfoResult;
import edu.stanford.bmir.protege.web.shared.dispatch.actions.*;
import edu.stanford.bmir.protege.web.shared.icd.*;
import edu.stanford.bmir.protege.web.shared.permissions.PermissionDeniedException;
import edu.stanford.bmir.protege.web.shared.project.*;

Expand Down Expand Up @@ -80,6 +77,7 @@ public CreateNewProjectView getView() {
public void start() {
view.clear();
view.setFileUploadEnabled(loggedInUserManager.isAllowedApplicationAction(UPLOAD_PROJECT));
view.setFileSourceTypeOptions();
}

private boolean validate() {
Expand All @@ -98,28 +96,91 @@ public void validateAndCreateProject(ProjectCreatedHandler handler) {


private void submitCreateProjectRequest(ProjectCreatedHandler handler) {
if (view.isFileUploadSpecified()) {
String fileSourceType = view.getFileSourceType();
if (fileSourceType.equals("owl") && view.isFileUploadSpecified()) {
uploadSourcesAndCreateProject(handler);
}
else {
} else if (fileSourceType.equals("backup") && view.isFileUploadSpecified()) {
uploadProjectBackupAndCreateProjectFromBackup(handler);
} else {
createEmptyProject(handler);
}
}

private void createEmptyProject(ProjectCreatedHandler projectCreatedHandler) {
NewProjectSettings newProjectSettings = NewProjectSettings.get(loggedInUserManager.getLoggedInUserId(),
view.getProjectName(),
view.getProjectLanguage(),
view.getProjectDescription());
view.getProjectName(),
view.getProjectLanguage(),
view.getProjectDescription());
submitCreateNewProjectRequest(newProjectSettings, projectCreatedHandler);
}

private void uploadProjectBackupAndCreateProjectFromBackup(@Nonnull ProjectCreatedHandler projectCreatedHandler) {
checkNotNull(projectCreatedHandler);
progressDisplay.displayProgress("Uploading file", "Uploading file. Please wait.");
dispatchServiceManager.execute(new GetUserInfoAction(),
info -> createProjectFromProjectBackupForUser(info, projectCreatedHandler));
}

private void createProjectFromProjectBackupForUser(GetUserInfoResult userInfo,
ProjectCreatedHandler projectCreatedHandler) {
String fileUploadElementId = view.getFileUploadElementId();
FileUploader fileUploader = new FileUploader(applicationEnvironmentManager.getAppEnvVariables().getFileUploadUrl());
fileUploader.uploadFile(fileUploadElementId,
userInfo.getToken(),
fileSubmissionId -> handleProjectBackupFilesSubmissionSuccess(projectCreatedHandler, fileSubmissionId),
this::handleFileSubmissionError);
}

private void handleProjectBackupFilesSubmissionSuccess(ProjectCreatedHandler projectCreatedHandler, String fileSubmissionId) {
progressDisplay.hideProgress();
handleCreateNewProjectFromProjectBackup(projectCreatedHandler,
new DocumentId(fileSubmissionId));
}

private void handleCreateNewProjectFromProjectBackup(ProjectCreatedHandler projectCreatedHandler, DocumentId documentId) {
NewProjectSettings newProjectSettings = NewProjectSettings.get(loggedInUserManager.getLoggedInUserId(),
view.getProjectName(),
view.getProjectLanguage(),
view.getProjectDescription(),
documentId);
submitCreateNewProjectFromProjectBackupRequest(newProjectSettings, projectCreatedHandler);
}

private void submitCreateNewProjectFromProjectBackupRequest(NewProjectSettings newProjectSettings, ProjectCreatedHandler projectCreatedHandler) {
String uuid = UuidV4.uuidv4();
ProjectId newProjectId = ProjectId.get(uuid);
dispatchServiceManager.execute(new CreateNewProjectFromProjectBackupAction(newProjectId, newProjectSettings),
new DispatchServiceCallbackWithProgressDisplay<CreateNewProjectFromProjectBackupResult>(
errorDisplay,
progressDisplay) {
@Override
public String getProgressDisplayTitle() {
return "Creating project";
}

@Override
public String getProgressDisplayMessage() {
return "Please wait.";
}

@Override
public void handleSuccess(CreateNewProjectFromProjectBackupResult result) {
handleProjectCreationSuccess(projectCreatedHandler, result.getProjectDetails());
}

@Override
public void handleExecutionException(Throwable cause) {
handleProjectCreationException(cause);
}
});
}


private void uploadSourcesAndCreateProject(@Nonnull ProjectCreatedHandler projectCreatedHandler) {
checkNotNull(projectCreatedHandler);
progressDisplay.displayProgress("Uploading file", "Uploading file. Please wait.");
dispatchServiceManager.execute(new GetUserInfoAction(),
info -> createProjectForUser(info, projectCreatedHandler));
info -> createProjectForUser(info, projectCreatedHandler));
}

private void createProjectForUser(GetUserInfoResult userInfo,
Expand All @@ -128,9 +189,9 @@ private void createProjectForUser(GetUserInfoResult userInfo,
String fileUploadElementId = view.getFileUploadElementId();
FileUploader fileUploader = new FileUploader(applicationEnvironmentManager.getAppEnvVariables().getFileUploadUrl());
fileUploader.uploadFile(fileUploadElementId,
userInfo.getToken(),
fileSubmissionId -> handleFileSubmissionSuccess(projectCreatedHandler, fileSubmissionId),
this::handleFileSubmissionError);
userInfo.getToken(),
fileSubmissionId -> handleFileSubmissionSuccess(projectCreatedHandler, fileSubmissionId),
this::handleFileSubmissionError);
}

private void handleFileSubmissionError(int errorCode) {
Expand All @@ -142,15 +203,15 @@ private void handleFileSubmissionSuccess(CreateNewProjectPresenter.ProjectCreate
String fileSubmissionId) {
progressDisplay.hideProgress();
handleCreateNewProjectFromUploadedSources(projectCreatedHandler,
new DocumentId(fileSubmissionId));
new DocumentId(fileSubmissionId));
}

private void handleCreateNewProjectFromUploadedSources(ProjectCreatedHandler projectCreatedHandler, DocumentId documentId) {
NewProjectSettings newProjectSettings = NewProjectSettings.get(loggedInUserManager.getLoggedInUserId(),
view.getProjectName(),
view.getProjectLanguage(),
view.getProjectDescription(),
documentId);
view.getProjectName(),
view.getProjectLanguage(),
view.getProjectDescription(),
documentId);
submitCreateNewProjectRequest(newProjectSettings, projectCreatedHandler);
}

Expand All @@ -159,46 +220,51 @@ private void submitCreateNewProjectRequest(@Nonnull NewProjectSettings newProjec
String uuid = UuidV4.uuidv4();
ProjectId newProjectId = ProjectId.get(uuid);
dispatchServiceManager.execute(new CreateNewProjectAction(newProjectId, newProjectSettings),
new DispatchServiceCallbackWithProgressDisplay<CreateNewProjectResult>(
errorDisplay,
progressDisplay) {
@Override
public String getProgressDisplayTitle() {
return "Creating project";
}

@Override
public String getProgressDisplayMessage() {
return "Please wait.";
}

@Override
public void handleSuccess(CreateNewProjectResult result) {
projectCreatedHandler.handleProjectCreated();
eventBus.fireEvent(new ProjectCreatedEvent(result.getProjectDetails()));
}

@Override
public void handleExecutionException(Throwable cause) {
if (cause instanceof PermissionDeniedException) {
messageBox.showMessage(
"You do not have permission to create new projects");
}
else if (cause instanceof ProjectAlreadyRegisteredException) {
ProjectAlreadyRegisteredException ex = (ProjectAlreadyRegisteredException) cause;
String projectName = ex.getProjectId().getId();
messageBox.showMessage("The project name " + projectName + " is already registered. Please try a different name.");
}
else if (cause instanceof ProjectDocumentExistsException) {
ProjectDocumentExistsException ex = (ProjectDocumentExistsException) cause;
String projectName = ex.getProjectId().getId();
messageBox.showMessage(
"There is already a non-empty project on the server with the id " + projectName + ". This project has NOT been overwritten. Please contact the administrator to resolve this issue.");
}
else {
messageBox.showMessage(cause.getMessage());
}
}
});
}
}
new DispatchServiceCallbackWithProgressDisplay<CreateNewProjectResult>(
errorDisplay,
progressDisplay) {
@Override
public String getProgressDisplayTitle() {
return "Creating project";
}

@Override
public String getProgressDisplayMessage() {
return "Please wait.";
}

@Override
public void handleSuccess(CreateNewProjectResult result) {
handleProjectCreationSuccess(projectCreatedHandler, result.getProjectDetails());
}

@Override
public void handleExecutionException(Throwable cause) {
handleProjectCreationException(cause);
}
});
}

private void handleProjectCreationSuccess(ProjectCreatedHandler projectCreatedHandler, ProjectDetails projectDetails) {
projectCreatedHandler.handleProjectCreated();
eventBus.fireEvent(new ProjectCreatedEvent(projectDetails));
}

private void handleProjectCreationException(Throwable cause) {
if (cause instanceof PermissionDeniedException) {
messageBox.showMessage(
"You do not have permission to create new projects");
} else if (cause instanceof ProjectAlreadyRegisteredException) {
ProjectAlreadyRegisteredException ex = (ProjectAlreadyRegisteredException) cause;
String projectName = ex.getProjectId().getId();
messageBox.showMessage("The project name " + projectName + " is already registered. Please try a different name.");
} else if (cause instanceof ProjectDocumentExistsException) {
ProjectDocumentExistsException ex = (ProjectDocumentExistsException) cause;
String projectName = ex.getProjectId().getId();
messageBox.showMessage(
"There is already a non-empty project on the server with the id " + projectName + ". This project has NOT been overwritten. Please contact the administrator to resolve this issue.");
} else {
messageBox.showMessage(cause.getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,8 @@ public interface CreateNewProjectView extends HasInitialFocusable, IsWidget {

@Nonnull
String getFileUploadElementId();

String getFileSourceType();

void setFileSourceTypeOptions();
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ interface CreateNewProjectViewImplUiBinder extends UiBinder<HTMLPanel, CreateNew
@Nonnull
private final MessageBox messageBox;

@UiField
ListBox fileSourceType;

private HandlerRegistration submitCompleteHandlerRegistraion = () -> {};


Expand Down Expand Up @@ -138,4 +141,18 @@ protected void onAttach() {
projectNameField.setFocus(true);
fileUpload.getElement().setId(FILE_UPLOAD_ID);
}

@Override
public String getFileSourceType() {
int selectedIndex = fileSourceType.getSelectedIndex();
return selectedIndex >= 0 ? fileSourceType.getValue(selectedIndex) : "";
}

@Override
public void setFileSourceTypeOptions() {
fileSourceType.clear();
fileSourceType.addItem("OWL file", "owl");
fileSourceType.addItem("Backup files", "backup");
fileSourceType.setSelectedIndex(0); // Default to the first option
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
<ui:with field="wp" type="edu.stanford.bmir.protege.web.resources.WebProtegeClientBundle"/>
<ui:with field="msg" type="edu.stanford.bmir.protege.web.client.Messages"/>
<ui:style>
.main {

}
.formField {
}

.uploadContainer {
padding-top: 10px;
padding-bottom: 10px;
display: flex;
align-items: center;
gap: 10px;
}

.helpText {
max-width: 480px;
}
Expand All @@ -23,23 +26,34 @@
<g:TextBox ui:field="projectNameField" addStyleNames="{style.formField}"/>
</div>
<div class="{wp.style.formGroup}">
<g:Label text="{msg.projectSettings_language}" addStyleNames="{wp.style.formLabel}"/>
<g:Label text="{msg.projectSettings_language}" addStyleNames="{wp.style.formLabel}"/>
<primitive:DefaultLanguageEditor ui:field="projectLanguageField" addStyleNames="{style.formField}"/>
<label class="{wp.style.formHelpText} {style.helpText}"><ui:safehtml from="{msg.projectSettings_language_helpText}"/></label>
<label class="{wp.style.formHelpText} {style.helpText}">
<ui:safehtml from="{msg.projectSettings_language_helpText}"/>
</label>
</div>
<div class="{wp.style.formGroup}">
<g:Label text="{msg.projectSettings_description}" addStyleNames="{wp.style.formLabel}"/>
<g:Label text="{msg.projectSettings_description}" addStyleNames="{wp.style.formLabel}"/>
<g:TextArea ui:field="projectDescriptionField" addStyleNames="{style.formField}" visibleLines="5"/>
</div>
<g:HTMLPanel ui:field="fileUploadArea" addStyleNames="{wp.style.formGroup}">
<g:Label text="Create from existing sources" addStyleNames="{wp.style.formLabel}"/>
<g:HTMLPanel addStyleNames="{style.uploadContainer}">
<g:HTMLPanel>
<g:ListBox ui:field="fileSourceType">
<g:item value="owl">OWL file</g:item>
<g:item value="backup">Backup files</g:item>
</g:ListBox>
</g:HTMLPanel>
<g:FormPanel ui:field="formPanel">
<g:FileUpload ui:field="fileUpload"/>
</g:FormPanel>
</g:HTMLPanel>
<label class="{wp.style.formHelpText} {style.helpText}"><ui:safehtml from="{msg.projectSettings_owl_import_helpText}"/></label>
<label class="{wp.style.formHelpText} {style.helpText}">
<ui:safehtml from="{msg.projectSettings_owl_import_helpText}"/>
</label>
</g:HTMLPanel>


</g:HTMLPanel>
</ui:UiBinder>
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import edu.stanford.bmir.protege.web.shared.form.*;
import edu.stanford.bmir.protege.web.shared.frame.*;
import edu.stanford.bmir.protege.web.shared.hierarchy.*;
import edu.stanford.bmir.protege.web.shared.icd.GetClassAncestorsAction;
import edu.stanford.bmir.protege.web.shared.icd.*;
import edu.stanford.bmir.protege.web.shared.individuals.GetIndividualsAction;
import edu.stanford.bmir.protege.web.shared.individuals.GetIndividualsPageContainingIndividualAction;
import edu.stanford.bmir.protege.web.shared.issues.*;
Expand Down Expand Up @@ -241,7 +241,8 @@
@Type(value = UpdateLogicalDefinitionAction.class),
@Type(value = GetEntityLogicalDefinitionAction.class),
@Type(value = TranslateEventListAction.class),
@Type(value = SetNamedHierarchiesAction.class)
@Type(value = SetNamedHierarchiesAction.class),
@Type(value = CreateNewProjectFromProjectBackupAction.class)
})
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME)
public interface Action<R extends Result> extends IsSerializable {
Expand Down
Loading
Loading