Skip to content

Commit

Permalink
Merge pull request #5277 from Sage-Bionetworks/release-486
Browse files Browse the repository at this point in the history
Merge release 486 into develop
  • Loading branch information
jay-hodgson authored Feb 2, 2024
2 parents 8afed45 + de29cf4 commit 5b72df2
Show file tree
Hide file tree
Showing 4 changed files with 195 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
import org.sagebionetworks.web.client.widget.entity.browse.EntityFinderWidgetView;
import org.sagebionetworks.web.client.widget.entity.browse.EntityTreeBrowser;
import org.sagebionetworks.web.client.widget.entity.browse.FilesBrowser;
import org.sagebionetworks.web.client.widget.entity.controller.CreateDatasetOrCollection;
import org.sagebionetworks.web.client.widget.entity.controller.EntityRefProvEntryView;
import org.sagebionetworks.web.client.widget.entity.controller.ProvenanceEditorWidget;
import org.sagebionetworks.web.client.widget.entity.controller.ProvenanceListWidget;
Expand Down Expand Up @@ -782,6 +783,8 @@ public interface PortalGinInjector extends Ginjector {

CreateTableViewWizard getCreateTableViewWizard();

CreateDatasetOrCollection getCreateDatasetOrCollection();

SqlDefinedTableEditor getSqlDefinedTableEditor();

UploadTableModalWidget getUploadTableModalWidget();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
package org.sagebionetworks.web.client.widget.entity.controller;

import static com.google.common.util.concurrent.Futures.whenAllComplete;
import static com.google.common.util.concurrent.MoreExecutors.directExecutor;

import com.google.common.util.concurrent.FluentFuture;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.sagebionetworks.repo.model.Entity;
import org.sagebionetworks.repo.model.table.ColumnModel;
import org.sagebionetworks.repo.model.table.Dataset;
import org.sagebionetworks.repo.model.table.DatasetCollection;
import org.sagebionetworks.repo.model.table.EntityRefCollectionView;
import org.sagebionetworks.repo.model.table.Table;
import org.sagebionetworks.repo.model.table.ViewEntityType;
import org.sagebionetworks.web.client.DisplayUtils;
import org.sagebionetworks.web.client.GlobalApplicationState;
import org.sagebionetworks.web.client.PortalGinInjector;
import org.sagebionetworks.web.client.SynapseJavascriptClient;
import org.sagebionetworks.web.client.place.Synapse;
import org.sagebionetworks.web.client.widget.entity.PromptForValuesModalView;
import org.sagebionetworks.web.client.widget.entity.tabs.DatasetsTab;
import org.sagebionetworks.web.client.widget.table.modal.fileview.TableType;

public class CreateDatasetOrCollection implements IsWidget {

PromptForValuesModalView view;
SynapseJavascriptClient jsClient;
GlobalApplicationState globalAppState;
PortalGinInjector ginInjector;

@Inject
public CreateDatasetOrCollection(
PromptForValuesModalView view,
SynapseJavascriptClient jsClient,
GlobalApplicationState globalAppState,
PortalGinInjector ginInjector
) {
this.view = view;
this.jsClient = jsClient;
this.globalAppState = globalAppState;
this.ginInjector = ginInjector;
}

@Override
public Widget asWidget() {
return view.asWidget();
}

public void configure(String parentId, TableType type) {
boolean isDataset = TableType.dataset.equals(type);
boolean isDatasetCollection = TableType.dataset_collection.equals(type);
if (!(isDataset || isDatasetCollection)) {
DisplayUtils.showErrorMessage(
"Invalid type used to configure CreateDatasetOrCollection"
);
return;
}
String title = "", helpMarkdown = "";

if (TableType.dataset.equals(type)) {
title = "Create Dataset";
helpMarkdown = DatasetsTab.DATASETS_HELP;
} else {
title = "Create Dataset Collection";
helpMarkdown = DatasetsTab.DATASET_COLLECTIONS_HELP;
}
PromptForValuesModalView.Configuration.Builder builder =
ginInjector.getPromptForValuesModalConfigurationBuilder();
builder
.setTitle(title)
.addPrompt("Name", "")
// .addPrompt("Description", "")
.setCallback(values -> {
view.setLoading(true);
String name = values.get(0);
createEntity(parentId, name, "", type);
})
.addHelpWidget(helpMarkdown, DatasetsTab.DATASETS_HELP_URL);
view.configureAndShow(builder.buildConfiguration());
}

/**
* Create the Dataset or Dataset Collection
*
* @param name
*/
private void createEntity(
String parentId,
final String name,
final String description,
TableType tableType
) {
Table table;
List<ListenableFuture<?>> futures = new ArrayList<>();
ViewEntityType viewEntityType;
if (TableType.dataset.equals(tableType)) {
table = new Dataset();
viewEntityType = ViewEntityType.dataset;
} else {
table = new DatasetCollection();
viewEntityType = ViewEntityType.datasetcollection;
}
((EntityRefCollectionView) table).setItems(Collections.EMPTY_LIST); // Workaround for PLFM-7076
// For Datasets, automatically add the default columns (SWC-5917)
FluentFuture<List<ColumnModel>> defaultColumnsFuture =
jsClient.getDefaultColumnsForView(viewEntityType);
defaultColumnsFuture.addCallback(
new FutureCallback<List<ColumnModel>>() {
@Override
public void onSuccess(@Nullable List<ColumnModel> results) {
List<String> columnIds = new ArrayList<>();
for (ColumnModel col : results) {
columnIds.add(col.getId());
}
table.setColumnIds(columnIds);
}

@Override
public void onFailure(Throwable t) {
view.showError(
"Error fetching columns for the table: " + t.getMessage()
);
}
},
directExecutor()
);
futures.add(defaultColumnsFuture);

table.setName(name);
table.setParentId(parentId);
table.setDescription(description);
// Wait for all possible requests to complete before creating the entity.
FluentFuture.from(
whenAllComplete(futures)
.call(
() -> {
createEntity(table);
return null;
},
directExecutor()
)
);
}

private void createEntity(final Entity entity) {
jsClient
.createEntity(entity)
.addCallback(
new FutureCallback<Entity>() {
@Override
public void onSuccess(Entity table) {
// Go to the dataset page
view.setLoading(false);
view.hide();
globalAppState.getPlaceChanger().goTo(new Synapse(table.getId()));
}

@Override
public void onFailure(Throwable caught) {
view.showError(caught.getMessage());
}
},
directExecutor()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ public class EntityActionControllerImpl
IsACTMemberAsyncHandler isACTMemberAsyncHandler;
AddFolderDialogWidget addFolderDialogWidget;
CreateTableViewWizard createTableViewWizard;
CreateDatasetOrCollection createDatasetOrCollection;
SqlDefinedTableEditor sqlDefinedTableEditor;
boolean isShowingVersion = false;
WizardCallback entityUpdatedWizardCallback;
Expand Down Expand Up @@ -452,6 +453,14 @@ private CreateTableViewWizard getCreateTableViewWizard() {
return createTableViewWizard;
}

private CreateDatasetOrCollection getCreateDatasetOrCollection() {
if (createDatasetOrCollection == null) {
createDatasetOrCollection = ginInjector.getCreateDatasetOrCollection();
this.view.addWidget(createDatasetOrCollection.asWidget());
}
return createDatasetOrCollection;
}

private UploadTableModalWidget getUploadTableModalWidget() {
if (uploadTableModalWidget == null) {
uploadTableModalWidget = ginInjector.getUploadTableModalWidget();
Expand Down Expand Up @@ -1926,7 +1935,7 @@ public void onAddDataset() {
entityBundle,
Dataset.class.getName(),
() -> {
postCheckCreateTableOrView(TableType.dataset);
postCheckCreateDatasetOrCollection(TableType.dataset);
}
);
}
Expand All @@ -1936,7 +1945,7 @@ public void onAddDatasetCollection() {
entityBundle,
Dataset.class.getName(),
() -> {
postCheckCreateTableOrView(TableType.dataset_collection);
postCheckCreateDatasetOrCollection(TableType.dataset_collection);
}
);
}
Expand Down Expand Up @@ -1980,6 +1989,11 @@ public void onAddVirtualTable() {
);
}

private void postCheckCreateDatasetOrCollection(TableType type) {
CreateDatasetOrCollection dialog = getCreateDatasetOrCollection();
dialog.configure(entityBundle.getEntity().getId(), type);
}

private void postCheckCreateTableOrView(TableType table) {
CreateTableViewWizard wizard = getCreateTableViewWizard();
wizard.configure(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class DatasetsTab extends AbstractTablesTab {

public static final String DATASETS_HELP =
"Create a Draft Dataset and add File versions. Annotate, Mint DOI’s, and Publish your Dataset to share it with others.";
public static final String DATASET_COLLECTIONS_HELP =
"Dataset Collections allow you to collate Datasets found across one or more Synapse Projects or Folders. In order to add a Dataset to a Dataset Collection, it must be shared with you.";

public static final String DATASETS_AND_COLLECTIONS_HELP =
"Use Datasets to produce and distribute an immutable set of files found across one or more Projects or Folders. You can also create Dataset Collections which contain multiple Datasets.";
Expand Down

0 comments on commit 5b72df2

Please sign in to comment.