From 385650043d26b4f911e70de289279a6bd29c928c Mon Sep 17 00:00:00 2001 From: Jay Hodgson Date: Mon, 9 Dec 2024 16:17:45 -0800 Subject: [PATCH 1/2] SWC-7203: change to a project search query object --- .../web/client/view/ProfileViewImpl.java | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/sagebionetworks/web/client/view/ProfileViewImpl.java b/src/main/java/org/sagebionetworks/web/client/view/ProfileViewImpl.java index 3b1c29a13a..559ef61caa 100644 --- a/src/main/java/org/sagebionetworks/web/client/view/ProfileViewImpl.java +++ b/src/main/java/org/sagebionetworks/web/client/view/ProfileViewImpl.java @@ -14,6 +14,7 @@ import com.google.gwt.user.client.ui.SimplePanel; import com.google.gwt.user.client.ui.Widget; import com.google.inject.Inject; +import java.util.Collections; import org.gwtbootstrap3.client.ui.Alert; import org.gwtbootstrap3.client.ui.AnchorListItem; import org.gwtbootstrap3.client.ui.Button; @@ -29,6 +30,11 @@ import org.sagebionetworks.repo.model.Team; import org.sagebionetworks.repo.model.UserProfile; import org.sagebionetworks.repo.model.entity.query.SortDirection; +import org.sagebionetworks.repo.model.search.query.KeyValue; +import org.sagebionetworks.repo.model.search.query.SearchQuery; +import org.sagebionetworks.schema.adapter.JSONObjectAdapter; +import org.sagebionetworks.schema.adapter.JSONObjectAdapterException; +import org.sagebionetworks.web.client.DisplayConstants; import org.sagebionetworks.web.client.DisplayUtils; import org.sagebionetworks.web.client.context.SynapseReactClientFullContextPropsProvider; import org.sagebionetworks.web.client.cookie.CookieProvider; @@ -48,6 +54,7 @@ import org.sagebionetworks.web.client.widget.header.Header; import org.sagebionetworks.web.client.widget.table.v2.results.SortableTableHeaderImpl; import org.sagebionetworks.web.client.widget.team.OpenTeamInvitationsWidget; +import org.sagebionetworks.web.shared.SearchQueryUtils; public class ProfileViewImpl extends Composite implements ProfileView { @@ -220,6 +227,7 @@ public interface ProfileViewImplUiBinder CookieProvider cookies; SynapseReactClientFullContextPropsProvider propsProvider; + JSONObjectAdapter jsonObjectAdapter; @Inject public ProfileViewImpl( @@ -227,13 +235,15 @@ public ProfileViewImpl( Header headerWidget, CookieProvider cookies, SynapseReactClientFullContextPropsProvider propsProvider, - OrientationBanner orientationBanner + OrientationBanner orientationBanner, + JSONObjectAdapter jsonObjectAdapter ) { initWidget(binder.createAndBindUi(this)); this.headerWidget = headerWidget; this.cookies = cookies; this.propsProvider = propsProvider; this.orientationBanner = orientationBanner; + this.jsonObjectAdapter = jsonObjectAdapter; headerWidget.configure(); projectSearchTextBox .getElement() @@ -257,7 +267,7 @@ public ProfileViewImpl( presenter.goTo(new TeamSearch(teamSearchTextBox.getValue())) ); projectSearchButton.addClickHandler(event -> - presenter.goTo(new Search(projectSearchTextBox.getValue())) + presenter.goTo(new Search(getCurrentProjectSearchJSON())) ); moreChallengesButton.addClickHandler(event -> presenter.getMoreChallenges() @@ -288,6 +298,26 @@ public ProfileViewImpl( ); } + private String getCurrentProjectSearchJSON() { + String searchJSON = ""; + JSONObjectAdapter adapter = jsonObjectAdapter.createNew(); + try { + SearchQuery query = SearchQueryUtils.getDefaultSearchQuery(); + KeyValue projectsOnly = new KeyValue(); + projectsOnly.setKey("node_type"); + projectsOnly.setValue("project"); + query.getBooleanQuery().add(projectsOnly); + query.setQueryTerm( + Collections.singletonList(projectSearchTextBox.getValue()) + ); + query.writeToJSONObject(adapter); + searchJSON = adapter.toJSONString(); + } catch (JSONObjectAdapterException e) { + showErrorMessage(DisplayConstants.ERROR_GENERIC); + } + return searchJSON; + } + @Override public void setSortDirection( ProjectListSortColumn column, From dd32d0f966bc7f24f716e610d06a9ca8914fb935 Mon Sep 17 00:00:00 2001 From: Jay Hodgson Date: Tue, 10 Dec 2024 09:09:42 -0800 Subject: [PATCH 2/2] from code review --- .../sagebionetworks/web/client/presenter/SearchPresenter.java | 2 +- .../org/sagebionetworks/web/client/view/ProfileViewImpl.java | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/sagebionetworks/web/client/presenter/SearchPresenter.java b/src/main/java/org/sagebionetworks/web/client/presenter/SearchPresenter.java index c4735213c9..da621a539a 100644 --- a/src/main/java/org/sagebionetworks/web/client/presenter/SearchPresenter.java +++ b/src/main/java/org/sagebionetworks/web/client/presenter/SearchPresenter.java @@ -293,7 +293,7 @@ private SearchQuery checkForJson(String queryString) { SearchQuery query = getBaseSearchQuery(); query.setQueryTerm( - Arrays.asList(queryString.replace("%20", " ").split(" ")) + Arrays.asList(queryString.replace("%20", " ").split("\\s+")) ); // if query parses into SearchQuery, use that, otherwise use it as a diff --git a/src/main/java/org/sagebionetworks/web/client/view/ProfileViewImpl.java b/src/main/java/org/sagebionetworks/web/client/view/ProfileViewImpl.java index 559ef61caa..5977c59980 100644 --- a/src/main/java/org/sagebionetworks/web/client/view/ProfileViewImpl.java +++ b/src/main/java/org/sagebionetworks/web/client/view/ProfileViewImpl.java @@ -14,6 +14,7 @@ import com.google.gwt.user.client.ui.SimplePanel; import com.google.gwt.user.client.ui.Widget; import com.google.inject.Inject; +import java.util.Arrays; import java.util.Collections; import org.gwtbootstrap3.client.ui.Alert; import org.gwtbootstrap3.client.ui.AnchorListItem; @@ -307,8 +308,9 @@ private String getCurrentProjectSearchJSON() { projectsOnly.setKey("node_type"); projectsOnly.setValue("project"); query.getBooleanQuery().add(projectsOnly); + query.setQueryTerm( - Collections.singletonList(projectSearchTextBox.getValue()) + Arrays.asList(projectSearchTextBox.getValue().split("\\s+")) ); query.writeToJSONObject(adapter); searchJSON = adapter.toJSONString();