From b34bb22b156110ae229e126b234ac8e4c70bf0e5 Mon Sep 17 00:00:00 2001 From: Matthew Horridge Date: Wed, 12 Jun 2024 11:33:59 -0700 Subject: [PATCH] Initial support for a specific lang tag --- ...ormFieldDescriptorObjectListPresenter.java | 1 + .../protege/web/client/form/TextControl.java | 12 ++- .../form/TextControlDescriptorPresenter.java | 5 +- ...TextControlDescriptorPresenterFactory.java | 1 + .../form/TextControlDescriptorView.java | 7 +- .../form/TextControlDescriptorViewImpl.java | 52 ++++++++++- .../form/TextControlDescriptorViewImpl.ui.xml | 18 +++- .../project/CreateNewProjectPresenter.java | 47 +++++----- .../client/upload/FileUploadErrorHandler.java | 11 +++ .../upload/FileUploadSuccessHandler.java | 11 +++ .../web/client/upload/FileUploader.java | 58 ++++++++++++ .../upload/UploadFileDialogController.java | 59 ++++-------- .../FormFieldDescriptor_Serialization_IT.java | 6 +- .../field/SubFormControlDescriptor_IT.java | 1 + .../web/shared/form/field/StringType.java | 4 +- .../form/field/TextControlDescriptor.java | 10 +++ .../field/TextControlDescriptor_TestCase.java | 89 ++++++++++--------- 17 files changed, 271 insertions(+), 121 deletions(-) create mode 100644 webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/upload/FileUploadErrorHandler.java create mode 100644 webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/upload/FileUploadSuccessHandler.java create mode 100644 webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/upload/FileUploader.java diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/form/FormFieldDescriptorObjectListPresenter.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/form/FormFieldDescriptorObjectListPresenter.java index 0204da1e3f..4361c498e0 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/form/FormFieldDescriptorObjectListPresenter.java +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/form/FormFieldDescriptorObjectListPresenter.java @@ -29,6 +29,7 @@ private static FormFieldDescriptor getDefaultFormFieldDescriptor(UuidV4Provider FormFieldDeprecationStrategy.DELETE_VALUES, new TextControlDescriptor(LanguageMap.empty(), StringType.SIMPLE_STRING, + "", LineMode.SINGLE_LINE, "", LanguageMap.empty()), diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/form/TextControl.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/form/TextControl.java index 4c2c97af39..6a6802eab0 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/form/TextControl.java +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/form/TextControl.java @@ -14,7 +14,7 @@ import com.google.gwt.user.client.ui.HTMLPanel; import com.google.gwt.user.client.ui.Label; import edu.stanford.bmir.protege.web.client.primitive.*; -import edu.stanford.bmir.protege.web.shared.PrimitiveType; +import edu.stanford.bmir.protege.web.shared.*; import edu.stanford.bmir.protege.web.shared.entity.OWLLiteralData; import edu.stanford.bmir.protege.web.shared.entity.OWLPrimitiveData; import edu.stanford.bmir.protege.web.shared.form.ValidationStatus; @@ -164,7 +164,7 @@ private void displayErrorBorder() { } private void setStringType(StringType stringType) { - if(stringType == StringType.SIMPLE_STRING) { + if(stringType == StringType.SIMPLE_STRING || stringType == StringType.SPECIFIC_LANG_STRING) { languageEditor.setVisible(false); } else { @@ -231,7 +231,8 @@ public Optional getValue() { return Optional.empty(); } OWLLiteralData literalData = (OWLLiteralData) editedValue.get(); - if(literalData.getLiteral().getLiteral().trim().isEmpty()) { + String lexicalValue = literalData.getLiteral().getLiteral().trim(); + if(lexicalValue.isEmpty()) { return Optional.empty(); } if(stringType == StringType.SIMPLE_STRING) { @@ -243,6 +244,11 @@ public Optional getValue() { return Optional.of(TextControlData.get(descriptor, literalData.getLiteral())); } } + else if(stringType == StringType.SPECIFIC_LANG_STRING) { + String specificLangTag = descriptor.getSpecificLangTag().trim(); + OWLLiteral literalWithSepcificLang = DataFactory.getOWLLiteral(lexicalValue, specificLangTag); + return Optional.of(TextControlData.get(descriptor, literalWithSepcificLang)); + } else { return Optional.of(TextControlData.get(descriptor, literalData.getLiteral())); } diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/form/TextControlDescriptorPresenter.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/form/TextControlDescriptorPresenter.java index 268586e60b..9e438375f6 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/form/TextControlDescriptorPresenter.java +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/form/TextControlDescriptorPresenter.java @@ -5,7 +5,7 @@ import edu.stanford.bmir.protege.web.shared.form.field.LineMode; import edu.stanford.bmir.protege.web.shared.form.field.StringType; import edu.stanford.bmir.protege.web.shared.form.field.TextControlDescriptor; -import edu.stanford.bmir.protege.web.shared.lang.LanguageMap; +import edu.stanford.bmir.protege.web.shared.lang.*; import javax.annotation.Nonnull; import javax.inject.Inject; @@ -32,6 +32,7 @@ public TextControlDescriptorPresenter(@Nonnull TextControlDescriptorView view) { public FormControlDescriptor getFormFieldDescriptor() { return new TextControlDescriptor(view.getPlaceholder(), view.getStringType(), + view.getSpecificLangTag().map(LangTag::format).orElse(""), view.getLineMode(), view.getPattern(), view.getPatternViolationMessage()); @@ -46,6 +47,7 @@ public void setFormFieldDescriptor(@Nonnull FormControlDescriptor formControlDes TextControlDescriptor descriptor = (TextControlDescriptor) formControlDescriptor; view.setStringType(descriptor.getStringType()); view.setLineMode(descriptor.getLineMode()); + view.setSpecificLangTag(LangTag.get(descriptor.getSpecificLangTag())); view.setPatternViolationMessage(descriptor.getPlaceholder()); view.setPattern(descriptor.getPattern()); view.setPatternViolationMessage(descriptor.getPatternViolationErrorMessage()); @@ -55,6 +57,7 @@ public void setFormFieldDescriptor(@Nonnull FormControlDescriptor formControlDes public void clear() { view.setLineMode(LineMode.SINGLE_LINE); view.setStringType(StringType.SIMPLE_STRING); + view.setSpecificLangTag(LangTag.get("")); view.setPattern(""); view.setPatternViolationMessage(LanguageMap.empty()); view.setPlaceholder(LanguageMap.empty()); diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/form/TextControlDescriptorPresenterFactory.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/form/TextControlDescriptorPresenterFactory.java index 0b05a764db..e0325bbb2f 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/form/TextControlDescriptorPresenterFactory.java +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/form/TextControlDescriptorPresenterFactory.java @@ -44,6 +44,7 @@ public static TextControlDescriptor createDefault() { return new TextControlDescriptor( LanguageMap.empty(), StringType.SIMPLE_STRING, + "", LineMode.SINGLE_LINE, "", LanguageMap.empty() diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/form/TextControlDescriptorView.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/form/TextControlDescriptorView.java index 5614e5c7a7..5abe47c07f 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/form/TextControlDescriptorView.java +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/form/TextControlDescriptorView.java @@ -3,9 +3,10 @@ import com.google.gwt.user.client.ui.IsWidget; import edu.stanford.bmir.protege.web.shared.form.field.LineMode; import edu.stanford.bmir.protege.web.shared.form.field.StringType; -import edu.stanford.bmir.protege.web.shared.lang.LanguageMap; +import edu.stanford.bmir.protege.web.shared.lang.*; import javax.annotation.Nonnull; +import java.util.Optional; /** * Matthew Horridge @@ -39,4 +40,8 @@ public interface TextControlDescriptorView extends IsWidget { @Nonnull LanguageMap getPlaceholder(); + @Nonnull + Optional getSpecificLangTag(); + + void setSpecificLangTag(LangTag langTag); } diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/form/TextControlDescriptorViewImpl.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/form/TextControlDescriptorViewImpl.java index be6ec52e85..2a4a6673e3 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/form/TextControlDescriptorViewImpl.java +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/form/TextControlDescriptorViewImpl.java @@ -1,20 +1,24 @@ package edu.stanford.bmir.protege.web.client.form; import com.google.gwt.core.client.GWT; +import com.google.gwt.event.logical.shared.ValueChangeEvent; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.HTMLPanel; import com.google.gwt.user.client.ui.RadioButton; import com.google.gwt.user.client.ui.TextBox; +import edu.stanford.bmir.protege.web.client.primitive.LanguageEditor; import edu.stanford.bmir.protege.web.client.ui.Counter; import edu.stanford.bmir.protege.web.shared.form.field.LineMode; import edu.stanford.bmir.protege.web.shared.form.field.StringType; -import edu.stanford.bmir.protege.web.shared.lang.LanguageMap; +import edu.stanford.bmir.protege.web.shared.lang.*; import javax.annotation.Nonnull; import javax.inject.Inject; +import java.util.Optional; + import static com.google.common.base.Preconditions.checkNotNull; /** @@ -52,16 +56,38 @@ interface TextControlDescriptorViewImplUiBinder extends UiBinder event) { + updateVisibility(); + } + + private void updateVisibility() { + specificLangTagPanel.setVisible(specificLangString.getValue()); } @Override @@ -69,9 +95,13 @@ public void setStringType(@Nonnull StringType stringType) { if(stringType == StringType.SIMPLE_STRING) { simpleString.setValue(true); } - else { + else if(stringType == StringType.LANG_STRING) { langString.setValue(true); } + else { + specificLangString.setValue(true); + } + updateVisibility(); } @Nonnull @@ -80,9 +110,12 @@ public StringType getStringType() { if(simpleString.getValue()) { return StringType.SIMPLE_STRING; } - else { + else if(langString.getValue()) { return StringType.LANG_STRING; } + else { + return StringType.SPECIFIC_LANG_STRING; + } } @Override @@ -138,4 +171,15 @@ public void setPlaceholder(@Nonnull LanguageMap languageMap) { public LanguageMap getPlaceholder() { return placeholderEditor.getValue().orElse(LanguageMap.empty()); } + + @Nonnull + @Override + public Optional getSpecificLangTag() { + return specificLangTagEditor.getValue().map(LangTag::get); + } + + @Override + public void setSpecificLangTag(LangTag langTag) { + specificLangTagEditor.setValue(langTag.format()); + } } diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/form/TextControlDescriptorViewImpl.ui.xml b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/form/TextControlDescriptorViewImpl.ui.xml index eb9e3ffb95..eeaa505d95 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/form/TextControlDescriptorViewImpl.ui.xml +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/form/TextControlDescriptorViewImpl.ui.xml @@ -1,16 +1,30 @@ + xmlns:form="urn:import:edu.stanford.bmir.protege.web.client.form" + xmlns:primitive="urn:import:edu.stanford.bmir.protege.web.client.primitive"> + + .specificLangTag { + margin-top: 1em; + margin-left: 2em; + } + .specificLangTag__help { + max-width: 150px; + } + - + + + + + diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/project/CreateNewProjectPresenter.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/project/CreateNewProjectPresenter.java index 2a96e4bf20..5071b83e12 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/project/CreateNewProjectPresenter.java +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/project/CreateNewProjectPresenter.java @@ -7,10 +7,12 @@ import edu.stanford.bmir.protege.web.client.dispatch.ProgressDisplay; 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.FileUploadFileReader; +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.permissions.PermissionDeniedException; import edu.stanford.bmir.protege.web.shared.project.*; import edu.stanford.bmir.protege.web.shared.upload.SubmitFileAction; @@ -118,32 +120,35 @@ private void createEmptyProject(ProjectCreatedHandler projectCreatedHandler) { private void uploadSourcesAndCreateProject(@Nonnull ProjectCreatedHandler projectCreatedHandler) { checkNotNull(projectCreatedHandler); - String fileUploadElementId = view.getFileUploadElementId(); - FileUploadFileReader fileUploadFileReader = new FileUploadFileReader(); progressDisplay.displayProgress("Uploading file", "Uploading file. Please wait."); - fileUploadFileReader.readFiles(fileUploadElementId, fileContent -> { - progressDisplay.hideProgress(); - handleFileReadComplete(fileContent, projectCreatedHandler); - }, readError -> { - progressDisplay.hideProgress(); - messageBox.showAlert("Upload Failed", "Your file could not be uploaded."); - }); + dispatchServiceManager.execute(new GetUserInfoAction(), + info -> createProjectForUser(info, projectCreatedHandler)); } - private void handleFileReadComplete(@Nonnull String base64EncodedContent, - ProjectCreatedHandler projectCreatedHandler) { + private void createProjectForUser(GetUserInfoResult userInfo, + ProjectCreatedHandler projectCreatedHandler) { - dispatchServiceManager.execute(SubmitFileAction.create(base64EncodedContent), - busy -> {}, - result -> { - handleCreateNewProjectFromUploadedSources(projectCreatedHandler, result); - }); + String fileUploadElementId = view.getFileUploadElementId(); + FileUploader fileUploader = new FileUploader(); + fileUploader.uploadFile(fileUploadElementId, + userInfo.getToken(), + fileSubmissionId -> handleFileSubmissionSuccess(projectCreatedHandler, fileSubmissionId), + this::handleFileSubmissionError); + } + private void handleFileSubmissionError(int errorCode) { + messageBox.showMessage("Could not upload file", "Error code: " + errorCode); + progressDisplay.hideProgress(); + } + private void handleFileSubmissionSuccess(CreateNewProjectPresenter.ProjectCreatedHandler projectCreatedHandler, + String fileSubmissionId) { + progressDisplay.hideProgress(); + handleCreateNewProjectFromUploadedSources(projectCreatedHandler, + new DocumentId(fileSubmissionId)); } - private void handleCreateNewProjectFromUploadedSources(ProjectCreatedHandler projectCreatedHandler, SubmitFileResult result) { - DocumentId documentId = result.getFileSubmissionId(); + private void handleCreateNewProjectFromUploadedSources(ProjectCreatedHandler projectCreatedHandler, DocumentId documentId) { NewProjectSettings newProjectSettings = NewProjectSettings.get(loggedInUserManager.getLoggedInUserId(), view.getProjectName(), view.getProjectLanguage(), @@ -199,8 +204,4 @@ else if (cause instanceof ProjectDocumentExistsException) { } }); } - - public NewProjectInfo getNewProjectInfo() { - return new NewProjectInfo(view.getProjectName(), view.getProjectDescription()); - } } diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/upload/FileUploadErrorHandler.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/upload/FileUploadErrorHandler.java new file mode 100644 index 0000000000..cd8e805387 --- /dev/null +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/upload/FileUploadErrorHandler.java @@ -0,0 +1,11 @@ +package edu.stanford.bmir.protege.web.client.upload; + +/** + * Matthew Horridge + * Stanford Center for Biomedical Informatics Research + * 2024-06-10 + */ +public interface FileUploadErrorHandler { + + void handleFileUploadError(int statusCode); +} diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/upload/FileUploadSuccessHandler.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/upload/FileUploadSuccessHandler.java new file mode 100644 index 0000000000..6fceb7941a --- /dev/null +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/upload/FileUploadSuccessHandler.java @@ -0,0 +1,11 @@ +package edu.stanford.bmir.protege.web.client.upload; + +/** + * Matthew Horridge + * Stanford Center for Biomedical Informatics Research + * 2024-06-10 + */ +public interface FileUploadSuccessHandler { + + void handleFileUploadSuccess(String fileSubmissionId); +} diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/upload/FileUploader.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/upload/FileUploader.java new file mode 100644 index 0000000000..97bb68beed --- /dev/null +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/upload/FileUploader.java @@ -0,0 +1,58 @@ +package edu.stanford.bmir.protege.web.client.upload; + +/** + * Matthew Horridge + * Stanford Center for Biomedical Informatics Research + * 2024-06-10 + */ +public class FileUploader { + + private static final String END_POINT = "/files/submit"; + + /** + * Upload a file that is retrieved from a FileInput element + * @param fileInputId The Id of the file input element + * @param token The authentication token to use when uploading the file + * @param successHandler The handler that will be called if the upload succeeds. + * @param errorHandler The handle that will be called if the upload fails. + */ + public void uploadFile(String fileInputId, + String token, + FileUploadSuccessHandler successHandler, + FileUploadErrorHandler errorHandler) { + uploadFileNative(fileInputId, END_POINT, token, successHandler, errorHandler); + } + + private native void uploadFileNative(String fileInputId, String endPoint, String token, + FileUploadSuccessHandler successHandler, + FileUploadErrorHandler errorHandler)/*-{ + + var fileElement = $doc.getElementById(fileInputId); + var file = fileElement.files[0]; + + var formData = new FormData(); + formData.append("file", file); + + var xhr = new XMLHttpRequest(); + xhr.open("POST", endPoint, true); + var authHeader = "bearer " + token; + xhr.setRequestHeader('Authorization', authHeader); + xhr.onreadystatechange = function () { + if (xhr.readyState === 4) { + if(xhr.status === 200) { + var submissionId = xhr.responseText.substring(1, xhr.responseText.length - 1); + successHandler.@edu.stanford.bmir.protege.web.client.upload.FileUploadSuccessHandler::handleFileUploadSuccess(*)(submissionId); + } + else { + var errorCode = xhr.status; + errorHandler.@edu.stanford.bmir.protege.web.client.upload.FileUploadErrorHandler::handleFileUploadError(*)(errorCode); + } + } + }; + + console.log("About to send form data"); + // Initiate a multipart/form-data upload + xhr.send(formData); + + }-*/; +} diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/upload/UploadFileDialogController.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/upload/UploadFileDialogController.java index 34ce59d2ee..7c679a20c3 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/upload/UploadFileDialogController.java +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/upload/UploadFileDialogController.java @@ -2,18 +2,15 @@ import com.google.auto.factory.AutoFactory; import com.google.auto.factory.Provided; -import com.google.gwt.core.client.GWT; -import com.google.gwt.user.client.ui.FormPanel; import com.google.gwt.user.client.ui.Widget; 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.library.dlg.*; -import edu.stanford.bmir.protege.web.client.progress.ProgressMonitor; import edu.stanford.bmir.protege.web.client.uuid.UuidV4; -import edu.stanford.bmir.protege.web.shared.upload.SubmitFileAction; -import edu.stanford.bmir.protege.web.shared.upload.SubmitFileResult; +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 javax.annotation.Nonnull; @@ -29,8 +26,6 @@ public class UploadFileDialogController extends WebProtegeOKCancelDialogControll private final DispatchServiceManager dispatch; - private final DispatchErrorMessageDisplay errorMessageDisplay; - private final ProgressDisplay progressDisplay; private UploadFileDialogForm form = new UploadFileDialogForm(); @@ -38,50 +33,32 @@ public class UploadFileDialogController extends WebProtegeOKCancelDialogControll public UploadFileDialogController(String title, final UploadFileResultHandler resultHandler, @Provided DispatchServiceManager dispatch, - @Provided DispatchErrorMessageDisplay errorMessageDisplay, @Provided ProgressDisplay progressDisplay) { super(title); this.dispatch = dispatch; - this.errorMessageDisplay = errorMessageDisplay; this.progressDisplay = progressDisplay; setDialogButtonHandler(DialogButton.OK, (data, closer) -> handleButtonPress(resultHandler, closer)); form.getFileUpload().getElement().setId(UuidV4.uuidv4()); } private void handleButtonPress(UploadFileResultHandler resultHandler, WebProtegeDialogCloser closer) { - ProgressMonitor.get().showProgressMonitor("Preparing file", "Preparing file for upload. Please wait."); - FileUploadFileReader reader = new FileUploadFileReader(); - reader.readFiles(form.getFileUpload().getElement().getId(), - content -> { - dispatch.execute(SubmitFileAction.create(content), new DispatchServiceCallbackWithProgressDisplay(errorMessageDisplay, - progressDisplay) { - @Override - public String getProgressDisplayTitle() { - return "Uploading file"; - } - - @Override - public String getProgressDisplayMessage() { - return "Please wait"; - } + progressDisplay.displayProgress("Uploading file", "Uploading file. Please wait."); + dispatch.execute(new GetUserInfoAction(), userInfo -> { + String token = userInfo.getToken(); + String fileUploadId = form.getFileUpload().getElement().getId(); + FileUploader fileUploader = new FileUploader(); + fileUploader.uploadFile(fileUploadId, token, fileSubmissionId -> { + progressDisplay.hideProgress(); + closer.hide(); + resultHandler.handleFileUploaded(new DocumentId(fileSubmissionId)); + }, errorCode -> { + progressDisplay.hideProgress(); + closer.hide(); + resultHandler.handleFileUploadFailed("An error occurred uploading the file. Error code: " + errorCode); + }); + }); - @Override - public void handleSuccess(SubmitFileResult submitFileResult) { - closer.hide(); - resultHandler.handleFileUploaded(submitFileResult.getFileSubmissionId()); - } - @Override - public void handleErrorFinally(Throwable throwable) { - closer.hide(); - resultHandler.handleFileUploadFailed("An error occurred uploading the file: " + throwable.getMessage()); - } - }); - }, - errorHandler -> { - ProgressMonitor.get().hideProgressMonitor(); - resultHandler.handleFileUploadFailed("An error occurred preparing the file for upload"); - }); } @Nonnull diff --git a/webprotege-gwt-ui-server-core/src/test/java/edu/stanford/bmir/protege/web/server/form/FormFieldDescriptor_Serialization_IT.java b/webprotege-gwt-ui-server-core/src/test/java/edu/stanford/bmir/protege/web/server/form/FormFieldDescriptor_Serialization_IT.java index 2200c20013..6cafa4926d 100644 --- a/webprotege-gwt-ui-server-core/src/test/java/edu/stanford/bmir/protege/web/server/form/FormFieldDescriptor_Serialization_IT.java +++ b/webprotege-gwt-ui-server-core/src/test/java/edu/stanford/bmir/protege/web/server/form/FormFieldDescriptor_Serialization_IT.java @@ -38,7 +38,7 @@ public void shouldSerializeElementWithoutOwlBinding() throws IOException { LanguageMap.empty(), FieldRun.START, FormFieldDeprecationStrategy.DELETE_VALUES, - new TextControlDescriptor(LanguageMap.empty(), StringType.SIMPLE_STRING, LineMode.SINGLE_LINE, "", LanguageMap.empty()), + new TextControlDescriptor(LanguageMap.empty(), StringType.SIMPLE_STRING, "en", LineMode.SINGLE_LINE, "", LanguageMap.empty()), Repeatability.NON_REPEATABLE, Optionality.REQUIRED, true, @@ -58,7 +58,7 @@ public void shouldSerializeElementWithOwlPropertyBinding() throws IOException { LanguageMap.empty(), FieldRun.START, FormFieldDeprecationStrategy.DELETE_VALUES, - new TextControlDescriptor(LanguageMap.empty(), StringType.SIMPLE_STRING, LineMode.SINGLE_LINE, "", LanguageMap.empty()), + new TextControlDescriptor(LanguageMap.empty(), StringType.SIMPLE_STRING, "en", LineMode.SINGLE_LINE, "", LanguageMap.empty()), Repeatability.NON_REPEATABLE, Optionality.REQUIRED, true, @@ -79,7 +79,7 @@ public void shouldSerializeElementWithOwlClassBinding() throws IOException { LanguageMap.empty(), FieldRun.START, FormFieldDeprecationStrategy.DELETE_VALUES, - new TextControlDescriptor(LanguageMap.empty(), StringType.SIMPLE_STRING, LineMode.SINGLE_LINE, "", LanguageMap.empty()), + new TextControlDescriptor(LanguageMap.empty(), StringType.SIMPLE_STRING, "en", LineMode.SINGLE_LINE, "", LanguageMap.empty()), Repeatability.NON_REPEATABLE, Optionality.REQUIRED, true, diff --git a/webprotege-gwt-ui-server-core/src/test/java/edu/stanford/bmir/protege/web/shared/form/field/SubFormControlDescriptor_IT.java b/webprotege-gwt-ui-server-core/src/test/java/edu/stanford/bmir/protege/web/shared/form/field/SubFormControlDescriptor_IT.java index 4b307599fd..00d1606932 100644 --- a/webprotege-gwt-ui-server-core/src/test/java/edu/stanford/bmir/protege/web/shared/form/field/SubFormControlDescriptor_IT.java +++ b/webprotege-gwt-ui-server-core/src/test/java/edu/stanford/bmir/protege/web/shared/form/field/SubFormControlDescriptor_IT.java @@ -49,6 +49,7 @@ public void shouldSerializeAndDeserialize() throws IOException { new TextControlDescriptor( LanguageMap.empty(), StringType.SIMPLE_STRING, + "en", LineMode.SINGLE_LINE, "Pattern", LanguageMap.empty() diff --git a/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/form/field/StringType.java b/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/form/field/StringType.java index 69e2694427..0f8c03cf01 100644 --- a/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/form/field/StringType.java +++ b/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/form/field/StringType.java @@ -9,5 +9,7 @@ public enum StringType { SIMPLE_STRING, - LANG_STRING + LANG_STRING, + + SPECIFIC_LANG_STRING } diff --git a/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/form/field/TextControlDescriptor.java b/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/form/field/TextControlDescriptor.java index 039169647a..ddab02ce42 100644 --- a/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/form/field/TextControlDescriptor.java +++ b/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/form/field/TextControlDescriptor.java @@ -24,6 +24,8 @@ public class TextControlDescriptor implements FormControlDescriptor { private StringType stringType = StringType.SIMPLE_STRING; + private String specificLangTag = ""; + private LineMode lineMode = LineMode.SINGLE_LINE; private String pattern = ""; @@ -35,10 +37,12 @@ private TextControlDescriptor() { public TextControlDescriptor(@Nonnull LanguageMap placeholder, @Nonnull StringType stringType, + @Nonnull String specificLangTag, @Nonnull LineMode lineMode, @Nonnull String pattern, @Nonnull LanguageMap patternViolationErrorMessage) { this.placeholder = checkNotNull(placeholder); + this.specificLangTag = checkNotNull(specificLangTag); this.stringType = checkNotNull(stringType); this.lineMode = checkNotNull(lineMode); this.pattern = checkNotNull(pattern); @@ -54,6 +58,7 @@ public static TextControlDescriptor getDefault() { return new TextControlDescriptor( LanguageMap.empty(), StringType.SIMPLE_STRING, + "", LineMode.SINGLE_LINE, "", LanguageMap.empty() @@ -124,6 +129,11 @@ public StringType getStringType() { return stringType; } + @Nonnull + public String getSpecificLangTag() { + return specificLangTag; + } + @Override public int hashCode() { return Objects.hashCode(placeholder, stringType, pattern, patternViolationErrorMessage, lineMode); diff --git a/webprotege-gwt-ui-shared/src/test/java/edu/stanford/bmir/protege/web/shared/form/field/TextControlDescriptor_TestCase.java b/webprotege-gwt-ui-shared/src/test/java/edu/stanford/bmir/protege/web/shared/form/field/TextControlDescriptor_TestCase.java index 224eb3a51e..feb457b737 100644 --- a/webprotege-gwt-ui-shared/src/test/java/edu/stanford/bmir/protege/web/shared/form/field/TextControlDescriptor_TestCase.java +++ b/webprotege-gwt-ui-shared/src/test/java/edu/stanford/bmir/protege/web/shared/form/field/TextControlDescriptor_TestCase.java @@ -4,143 +4,148 @@ import edu.stanford.bmir.protege.web.shared.lang.LanguageMap; import org.hamcrest.Matchers; import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.*; import org.junit.runner.RunWith; import org.mockito.runners.MockitoJUnitRunner; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; +import static org.junit.jupiter.api.Assertions.assertThrows; @RunWith(MockitoJUnitRunner.class) public class TextControlDescriptor_TestCase { private TextControlDescriptor textFieldDescriptor; - private LanguageMap placeholder = LanguageMap.of("en", "The placeholder"); + private final LanguageMap placeholder = LanguageMap.of("en", "The placeholder"); - private StringType stringType = StringType.SIMPLE_STRING; + private final StringType stringType = StringType.SIMPLE_STRING; - private LineMode lineMode = LineMode.SINGLE_LINE; + private final String specificLangTag = ""; - private String pattern = "The pattern"; + private final LineMode lineMode = LineMode.SINGLE_LINE; - private LanguageMap patternViolationErrorMessage = LanguageMap.of("en", "The patternViolationErrorMessage"); + private final String pattern = "The pattern"; - @Before + private final LanguageMap patternViolationErrorMessage = LanguageMap.of("en", "The patternViolationErrorMessage"); + + @BeforeEach public void setUp() - throws Exception + throws Exception { - textFieldDescriptor = new TextControlDescriptor(placeholder, stringType, lineMode, pattern, patternViolationErrorMessage); + textFieldDescriptor = new TextControlDescriptor(placeholder, stringType, specificLangTag, lineMode, pattern, patternViolationErrorMessage); } @SuppressWarnings("ConstantConditions") - @Test(expected = NullPointerException.class) + @org.junit.jupiter.api.Test public void shouldThrowNullPointerExceptionIf_placeholder_IsNull() { - new TextControlDescriptor(null, stringType, lineMode, pattern, patternViolationErrorMessage); + assertThrows(NullPointerException.class, () -> { + new TextControlDescriptor(null, stringType, specificLangTag, lineMode, pattern, patternViolationErrorMessage); + }); } - @Test + @org.junit.jupiter.api.Test public void shouldReturnSupplied_placeholder() { assertThat(textFieldDescriptor.getPlaceholder(), is(this.placeholder)); } @SuppressWarnings("ConstantConditions") - @Test(expected = NullPointerException.class) + // @Test(expected = NullPointerException.class) public void shouldThrowNullPointerExceptionIf_stringType_IsNull() { - new TextControlDescriptor(placeholder, null, lineMode, pattern, patternViolationErrorMessage); + new TextControlDescriptor(placeholder, null, specificLangTag, lineMode, pattern, patternViolationErrorMessage); } - @Test + @org.junit.jupiter.api.Test public void shouldReturnSupplied_stringType() { assertThat(textFieldDescriptor.getStringType(), is(this.stringType)); } @SuppressWarnings("ConstantConditions") - @Test(expected = NullPointerException.class) + // @Test(expected = NullPointerException.class) public void shouldThrowNullPointerExceptionIf_lineMode_IsNull() { - new TextControlDescriptor(placeholder, stringType, null, pattern, patternViolationErrorMessage); + new TextControlDescriptor(placeholder, stringType, specificLangTag, null, pattern, patternViolationErrorMessage); } - @Test + @org.junit.jupiter.api.Test public void shouldReturnSupplied_lineMode() { assertThat(textFieldDescriptor.getLineMode(), is(this.lineMode)); } @SuppressWarnings("ConstantConditions") - @Test(expected = NullPointerException.class) + // @Test(expected = NullPointerException.class) public void shouldThrowNullPointerExceptionIf_pattern_IsNull() { - new TextControlDescriptor(placeholder, stringType, lineMode, null, patternViolationErrorMessage); + new TextControlDescriptor(placeholder, stringType, specificLangTag, lineMode, null, patternViolationErrorMessage); } - @Test + @org.junit.jupiter.api.Test public void shouldReturnSupplied_pattern() { assertThat(textFieldDescriptor.getPattern(), is(this.pattern)); } @SuppressWarnings("ConstantConditions") - @Test(expected = NullPointerException.class) + // @Test(expected = NullPointerException.class) public void shouldThrowNullPointerExceptionIf_patternViolationErrorMessage_IsNull() { - new TextControlDescriptor(placeholder, stringType, lineMode, pattern, null); + new TextControlDescriptor(placeholder, stringType, specificLangTag, lineMode, pattern, null); } - @Test + @org.junit.jupiter.api.Test public void shouldReturnSupplied_patternViolationErrorMessage() { assertThat(textFieldDescriptor.getPatternViolationErrorMessage(), is(this.patternViolationErrorMessage)); } - @Test + @org.junit.jupiter.api.Test public void shouldBeEqualToSelf() { assertThat(textFieldDescriptor, is(textFieldDescriptor)); } - @Test + @org.junit.jupiter.api.Test @SuppressWarnings("ObjectEqualsNull") public void shouldNotBeEqualToNull() { assertThat(textFieldDescriptor.equals(null), is(false)); } - @Test + @org.junit.jupiter.api.Test public void shouldBeEqualToOther() { - assertThat(textFieldDescriptor, is(new TextControlDescriptor(placeholder, stringType, lineMode, pattern, patternViolationErrorMessage))); + assertThat(textFieldDescriptor, is(new TextControlDescriptor(placeholder, stringType, specificLangTag, lineMode, pattern, patternViolationErrorMessage))); } - @Test + @org.junit.jupiter.api.Test public void shouldNotBeEqualToOtherThatHasDifferent_placeholder() { - assertThat(textFieldDescriptor, is(not(new TextControlDescriptor(LanguageMap.of("en", "String-1a3f1304-8c2f-48b2-8c60-3407b27d579f"), stringType, lineMode, pattern, patternViolationErrorMessage)))); + assertThat(textFieldDescriptor, is(not(new TextControlDescriptor(LanguageMap.of("en", "String-1a3f1304-8c2f-48b2-8c60-3407b27d579f"), stringType, specificLangTag, lineMode, pattern, patternViolationErrorMessage)))); } - @Test + @org.junit.jupiter.api.Test public void shouldNotBeEqualToOtherThatHasDifferent_stringType() { - assertThat(textFieldDescriptor, is(not(new TextControlDescriptor(placeholder, StringType.LANG_STRING, lineMode, pattern, patternViolationErrorMessage)))); + assertThat(textFieldDescriptor, is(not(new TextControlDescriptor(placeholder, StringType.LANG_STRING, "de", lineMode, pattern, patternViolationErrorMessage)))); } - @Test + @org.junit.jupiter.api.Test public void shouldNotBeEqualToOtherThatHasDifferent_lineMode() { - assertThat(textFieldDescriptor, is(not(new TextControlDescriptor(placeholder, stringType, LineMode.MULTI_LINE, pattern, patternViolationErrorMessage)))); + assertThat(textFieldDescriptor, is(not(new TextControlDescriptor(placeholder, stringType, specificLangTag, LineMode.MULTI_LINE, pattern, patternViolationErrorMessage)))); } - @Test + @org.junit.jupiter.api.Test public void shouldNotBeEqualToOtherThatHasDifferent_pattern() { - assertThat(textFieldDescriptor, is(not(new TextControlDescriptor(placeholder, stringType, lineMode, "String-ac3398da-4b52-48b5-a858-1f8571134db7", patternViolationErrorMessage)))); + assertThat(textFieldDescriptor, is(not(new TextControlDescriptor(placeholder, stringType, specificLangTag, lineMode, "String-ac3398da-4b52-48b5-a858-1f8571134db7", patternViolationErrorMessage)))); } - @Test + @org.junit.jupiter.api.Test public void shouldNotBeEqualToOtherThatHasDifferent_patternViolationErrorMessage() { - assertThat(textFieldDescriptor, is(not(new TextControlDescriptor(placeholder, stringType, lineMode, pattern, LanguageMap.of("en", "String-1abd718d-0eb4-4530-b465-02aed8dd66a2"))))); + assertThat(textFieldDescriptor, is(not(new TextControlDescriptor(placeholder, stringType, specificLangTag, lineMode, pattern, LanguageMap.of("en", "String-1abd718d-0eb4-4530-b465-02aed8dd66a2"))))); } - @Test + @org.junit.jupiter.api.Test public void shouldBeEqualToOtherHashCode() { - assertThat(textFieldDescriptor.hashCode(), is(new TextControlDescriptor(placeholder, stringType, lineMode, pattern, patternViolationErrorMessage).hashCode())); + assertThat(textFieldDescriptor.hashCode(), is(new TextControlDescriptor(placeholder, stringType, specificLangTag, lineMode, pattern, patternViolationErrorMessage).hashCode())); } - @Test + @org.junit.jupiter.api.Test public void shouldImplementToString() { assertThat(textFieldDescriptor.toString(), Matchers.startsWith("TextControlDescriptor")); } - @Test + @org.junit.jupiter.api.Test public void should_getAssociatedType() { assertThat(textFieldDescriptor.getAssociatedType(), is("TEXT")); }