Skip to content

Commit

Permalink
Merge branch 'master' into master-who
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewhorridge committed Jun 16, 2024
2 parents d23d00e + 2b445fe commit 4ccbff2
Show file tree
Hide file tree
Showing 19 changed files with 189 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Verify
on:
push:
branches-ignore:
- main
- master

jobs:
build:
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ name: Release
on:
push:
branches:
- master
- main*
- master*

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>edu.stanford.protege</groupId>
<artifactId>webprotege-gwt-ui</artifactId>
<version>5.0.9-WHO</version>
<version>5.0.13-WHO</version>
<packaging>pom</packaging>

<properties>
Expand Down
2 changes: 1 addition & 1 deletion webprotege-gwt-ui-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>edu.stanford.protege</groupId>
<artifactId>webprotege-gwt-ui</artifactId>
<version>5.0.9-WHO</version>
<version>5.0.13-WHO</version>
</parent>

<artifactId>webprotege-gwt-ui-client</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.LocalizableResource.DefaultLocale;
import org.checkerframework.checker.units.qual.K;

/**
* Matthew Horridge
Expand Down Expand Up @@ -231,4 +232,12 @@ public interface FormsMessages extends com.google.gwt.i18n.client.Messages {
@DefaultMessage("Deprecate")
@Key("deprecate")
String deprecate();

@DefaultMessage("Import and replace forms?")
@Key("forms.import.confirmation.title")
String confirmImportFormsIntoProject_title();

@DefaultMessage("Do you really want to import and replace all of the forms in this project? This cannot be undone.")
@Key("forms.import.confirmation.message")
String confirmImportFormsIntoProject_message();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package edu.stanford.bmir.protege.web.client.download;

import javax.annotation.Nonnull;

/**
* Matthew Horridge
* Stanford Center for Biomedical Informatics Research
* 2024-06-14
*/
public class FetchAndOpenInBrowserWindow {

/**
* GET the specified path and open the result as a blob in a new window
* @param path The path
* @param token The access token to use. This will be set in the authorization header.
*/
public static native void fetchUrlAndOpenInWindow(@Nonnull String path,
@Nonnull String token,
@Nonnull FetchAndOpenInBrowserWindowErrorHandler errorHandler)/*-{
var xhr = new XMLHttpRequest();
xhr.open('GET', path);
xhr.onreadystatechange = handler;
xhr.responseType = 'blob';
xhr.setRequestHeader('Authorization', 'Bearer ' + token);
xhr.send();
function handler() {
if (this.readyState === this.DONE) {
if (this.status === 200) {
// this.response is a Blob, because we set responseType above
var data_url = URL.createObjectURL(this.response);
$wnd.open(data_url, '_blank');
} else {
console.error('Error');
errorHandler.@edu.stanford.bmir.protege.web.client.download.FetchAndOpenInBrowserWindowErrorHandler::handleError(*)();
}
}
}
}-*/;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package edu.stanford.bmir.protege.web.client.download;

/**
* Matthew Horridge
* Stanford Center for Biomedical Informatics Research
* 2024-06-14
*/
public interface FetchAndOpenInBrowserWindowErrorHandler {

void handleError();
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package edu.stanford.bmir.protege.web.client.form;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import edu.stanford.bmir.protege.web.client.dispatch.*;
import edu.stanford.bmir.protege.web.client.download.FetchAndOpenInBrowserWindow;
import edu.stanford.bmir.protege.web.shared.dispatch.actions.GetUserInfoAction;
import edu.stanford.bmir.protege.web.shared.project.ProjectId;

import javax.annotation.Nonnull;
Expand All @@ -19,14 +21,27 @@ public class FormsDownloader {
@Nonnull
private final ProjectId projectId;

private final DispatchServiceManager dispatch;

private final MessageBoxErrorDisplay errorDisplay;

@Inject
public FormsDownloader(@Nonnull ProjectId projectId) {
public FormsDownloader(@Nonnull ProjectId projectId, DispatchServiceManager dispatch, MessageBoxErrorDisplay errorDisplay) {
this.projectId = checkNotNull(projectId);
this.dispatch = checkNotNull(dispatch);
this.errorDisplay = checkNotNull(errorDisplay);
}

public void download() {
String baseURL = GWT.getHostPageBaseURL() + "data/";
String downloadURL = baseURL + "projects/" + projectId.getId() + "/forms";
Window.open(downloadURL, "Download forms", "");
dispatch.execute(new GetUserInfoAction(), result -> {
String baseURL = GWT.getHostPageBaseURL() + "data/";
String token = result.getToken();
FetchAndOpenInBrowserWindow.fetchUrlAndOpenInWindow("/data/projects/" + projectId.getId() + "/forms",
token,
() -> {
errorDisplay.displayGeneralErrorMessage("Download error",
"Could not download project forms");
});
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.google.gwt.http.client.*;
import edu.stanford.bmir.protege.web.client.dispatch.DispatchServiceManager;
import edu.stanford.bmir.protege.web.client.progress.HasBusy;
import edu.stanford.bmir.protege.web.shared.dispatch.actions.GetUserInfoAction;
import edu.stanford.bmir.protege.web.shared.form.*;
import edu.stanford.bmir.protege.web.shared.project.ProjectId;

Expand Down Expand Up @@ -67,32 +68,35 @@ public void importForms(@Nonnull String formJsonSerialization,
@Nonnull HasBusy busyIndicator,
@Nonnull Runnable completeHandler,
@Nonnull Runnable errorHandler) {
try {
String importFormsUrl = "/data/projects/" + projectId.getId() + "/forms";
RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.POST,
importFormsUrl);
requestBuilder.setRequestData(formJsonSerialization);
requestBuilder.setCallback(new RequestCallback() {
@Override
public void onResponseReceived(Request request, Response response) {
busyIndicator.setBusy(false);
completeHandler.run();
if(response.getStatusCode() != Response.SC_CREATED) {
errorHandler.run();
dispatch.execute(new GetUserInfoAction(), userInfo -> {
try {
String importFormsUrl = "/data/projects/" + projectId.getId() + "/forms";
RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.POST,
importFormsUrl);
requestBuilder.setRequestData(formJsonSerialization);
requestBuilder.setHeader("Authorization", "Bearer " + userInfo.getToken());
requestBuilder.setCallback(new RequestCallback() {
@Override
public void onResponseReceived(Request request, Response response) {
busyIndicator.setBusy(false);
completeHandler.run();
if(response.getStatusCode() >= 400) {
errorHandler.run();
}
}
}

@Override
public void onError(Request request, Throwable exception) {
busyIndicator.setBusy(false);
completeHandler.run();
}
});
requestBuilder.setHeader("Content-Type", "application/json");
busyIndicator.setBusy(true);
requestBuilder.send();
} catch (RequestException e) {
GWT.log(e.getMessage());
}
@Override
public void onError(Request request, Throwable exception) {
busyIndicator.setBusy(false);
completeHandler.run();
}
});
requestBuilder.setHeader("Content-Type", "application/json");
busyIndicator.setBusy(true);
requestBuilder.send();
} catch (RequestException e) {
GWT.log(e.getMessage());
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.*;
import edu.stanford.bmir.protege.web.client.FormsMessages;
import edu.stanford.bmir.protege.web.client.library.msgbox.InputBox;
import edu.stanford.bmir.protege.web.client.library.msgbox.MessageBox;
import edu.stanford.bmir.protege.web.client.library.dlg.DialogButton;
import edu.stanford.bmir.protege.web.client.library.msgbox.*;

import javax.annotation.Nonnull;
import javax.inject.Inject;
Expand Down Expand Up @@ -81,6 +81,17 @@ public void clear() {

@Override
public void displayImportFormsInputBox(Consumer<String> importFormsJson) {
messageBox.showConfirmBox(MessageStyle.ALERT,
formsMessages.confirmImportFormsIntoProject_title(),
formsMessages.confirmImportFormsIntoProject_message(),
DialogButton.NO,
() -> {},
DialogButton.YES,
() -> displayInputBox(importFormsJson),
DialogButton.NO);
}

private void displayInputBox(Consumer<String> importFormsJson) {
inputBox.showDialog(formsMessages.importFormsIntoProject_title(),
formsMessages.importFormsIntoProject_message(),
true, "", importFormsJson::accept);
Expand Down
2 changes: 1 addition & 1 deletion webprotege-gwt-ui-server-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>webprotege-gwt-ui</artifactId>
<groupId>edu.stanford.protege</groupId>
<version>5.0.9-WHO</version>
<version>5.0.13-WHO</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion webprotege-gwt-ui-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>edu.stanford.protege</groupId>
<artifactId>webprotege-gwt-ui</artifactId>
<version>5.0.9-WHO</version>
<version>5.0.13-WHO</version>
</parent>

<artifactId>webprotege-gwt-ui-server</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion webprotege-gwt-ui-shared-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>webprotege-gwt-ui</artifactId>
<groupId>edu.stanford.protege</groupId>
<version>5.0.9-WHO</version>
<version>5.0.13-WHO</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion webprotege-gwt-ui-shared/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>edu.stanford.protege</groupId>
<artifactId>webprotege-gwt-ui</artifactId>
<version>5.0.9-WHO</version>
<version>5.0.13-WHO</version>
</parent>

<artifactId>webprotege-gwt-ui-shared</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@
@Type(value = SetOntologyAnnotationsAction.class),
@Type(value = SetPerspectiveLayoutAction.class),
@Type(value = SetProjectFormDescriptorsAction.class),
@Type(value = SetProjectFormsAction.class),
@Type(value = SetProjectPrefixDeclarationsAction.class),
@Type(value = SetProjectSettingsAction.class),
@Type(value = SetProjectSharingSettingsAction.class),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@
@JsonSubTypes.Type(SetOntologyAnnotationsResult.class),
@JsonSubTypes.Type(SetPerspectiveLayoutResult.class),
@JsonSubTypes.Type(SetProjectFormDescriptorsResult.class),
@JsonSubTypes.Type(SetProjectFormsResult.class),
@JsonSubTypes.Type(SetProjectPrefixDeclarationsResult.class),
@JsonSubTypes.Type(SetProjectSettingsResult.class),
@JsonSubTypes.Type(SetProjectSharingSettingsResult.class),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package edu.stanford.bmir.protege.web.shared.form;

import com.fasterxml.jackson.annotation.JsonTypeName;
import com.google.auto.value.AutoValue;
import com.google.common.annotations.GwtCompatible;
import com.google.common.collect.ImmutableList;
import edu.stanford.bmir.protege.web.shared.dispatch.*;
import edu.stanford.bmir.protege.web.shared.project.ProjectId;

import javax.annotation.Nonnull;

/**
* Matthew Horridge
* Stanford Center for Biomedical Informatics Research
* 2024-06-15
*/
@JsonTypeName("webprotege.forms.SetProjectForms")
@AutoValue
@GwtCompatible(serializable = true)
public abstract class SetProjectFormsAction implements ProjectAction<SetProjectFormsResult> {

public SetProjectFormsAction get(@Nonnull ProjectId projectId,
@Nonnull ImmutableList<FormDescriptor> formDescriptors,
@Nonnull ImmutableList<EntityFormSelector> formSelectors) {
return new AutoValue_SetProjectFormsAction(projectId, formDescriptors, formSelectors);
}

@Nonnull
public abstract ProjectId getProjectId();

public abstract ImmutableList<FormDescriptor> getFormDescriptors();

public abstract ImmutableList<EntityFormSelector> getFormSelectors();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package edu.stanford.bmir.protege.web.shared.form;

import com.fasterxml.jackson.annotation.JsonTypeName;
import com.google.auto.value.AutoValue;
import com.google.common.annotations.GwtCompatible;
import edu.stanford.bmir.protege.web.shared.dispatch.Result;

/**
* Matthew Horridge
* Stanford Center for Biomedical Informatics Research
* 2024-06-15
*/
@JsonTypeName("webprotege.forms.SetProjectForms")
@AutoValue
@GwtCompatible(serializable = true)
public abstract class SetProjectFormsResult implements Result {

public static SetProjectFormsResult get() {
return new AutoValue_SetProjectFormsResult();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public abstract class EntityNameControlDataDto implements FormControlDataDto {

@JsonCreator
public static EntityNameControlDataDto get(@JsonProperty("descriptor") @Nonnull EntityNameControlDescriptor descriptor,
@JsonProperty("entityData") @Nonnull OWLEntityData entityData,
@JsonProperty("entity") @Nonnull OWLEntityData entityData,
@JsonProperty("depth") int depth) {
return new AutoValue_EntityNameControlDataDto(depth, descriptor, entityData);
}
Expand Down

0 comments on commit 4ccbff2

Please sign in to comment.