2017-09-27 18:38:30 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package org.gcube.portlets.user.workspace.client.view.windows;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import org.gcube.portlets.user.workspace.client.AppControllerExplorer;
|
|
|
|
import org.gcube.portlets.user.workspace.client.ConstantsExplorer;
|
2017-09-28 11:59:49 +02:00
|
|
|
import org.gcube.portlets.user.workspace.client.event.RefreshFolderEvent;
|
2017-09-27 18:38:30 +02:00
|
|
|
import org.gcube.portlets.user.workspace.client.model.FileModel;
|
|
|
|
import org.gcube.portlets.user.workspace.client.model.GcubeVRE;
|
|
|
|
import org.gcube.portlets.user.workspace.shared.TransferOnThreddsReport;
|
|
|
|
import org.gcube.portlets.widgets.wsexplorer.client.notification.WorkspaceExplorerSelectNotification.WorskpaceExplorerSelectNotificationListener;
|
|
|
|
import org.gcube.portlets.widgets.wsexplorer.client.select.WorkspaceExplorerSelectDialog;
|
|
|
|
import org.gcube.portlets.widgets.wsexplorer.shared.Item;
|
|
|
|
|
|
|
|
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
|
|
|
|
import com.extjs.gxt.ui.client.event.BaseEvent;
|
|
|
|
import com.extjs.gxt.ui.client.event.ButtonEvent;
|
|
|
|
import com.extjs.gxt.ui.client.event.ComponentEvent;
|
|
|
|
import com.extjs.gxt.ui.client.event.Events;
|
|
|
|
import com.extjs.gxt.ui.client.event.KeyListener;
|
|
|
|
import com.extjs.gxt.ui.client.event.KeyboardEvents;
|
|
|
|
import com.extjs.gxt.ui.client.event.Listener;
|
|
|
|
import com.extjs.gxt.ui.client.event.SelectionListener;
|
|
|
|
import com.extjs.gxt.ui.client.store.ListStore;
|
|
|
|
import com.extjs.gxt.ui.client.util.Format;
|
|
|
|
import com.extjs.gxt.ui.client.widget.Dialog;
|
2017-09-28 11:59:49 +02:00
|
|
|
import com.extjs.gxt.ui.client.widget.MessageBox;
|
2017-09-27 18:38:30 +02:00
|
|
|
import com.extjs.gxt.ui.client.widget.form.ComboBox;
|
|
|
|
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
|
|
|
|
import com.extjs.gxt.ui.client.widget.form.TextField;
|
|
|
|
import com.extjs.gxt.ui.client.widget.form.TriggerField;
|
|
|
|
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
|
|
|
|
import com.github.gwtbootstrap.client.ui.Label;
|
|
|
|
import com.github.gwtbootstrap.client.ui.constants.LabelType;
|
|
|
|
import com.google.gwt.core.client.GWT;
|
2017-09-28 11:59:49 +02:00
|
|
|
import com.google.gwt.user.client.Timer;
|
2017-09-27 18:38:30 +02:00
|
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Class DialogPublishOnThredds.
|
|
|
|
*
|
|
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
|
|
|
* Sep 27, 2017
|
|
|
|
*/
|
|
|
|
public class DialogPublishOnThredds extends Dialog {
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2017-09-28 16:57:10 +02:00
|
|
|
private int widthDialog = 570;
|
2017-09-27 18:38:30 +02:00
|
|
|
private TextField<String> txtCatalogueName;
|
|
|
|
private TriggerField<String> triggerFieldMetadataFolderName;
|
|
|
|
private ComboBox<GcubeVRE> selectVRE;
|
|
|
|
//private Button browse = new Button("Browse...");
|
|
|
|
private FileModel metadataFolder = null;
|
|
|
|
private FileModel theFolderToPublish;
|
|
|
|
private ListStore<GcubeVRE> vreStore = new ListStore<GcubeVRE>();
|
|
|
|
|
|
|
|
public static List<GcubeVRE> listOfVres = null;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instantiates a new dialog publish on thredds.
|
|
|
|
*
|
|
|
|
* @param theFolderToPublish the the folder to publish
|
|
|
|
*/
|
|
|
|
public DialogPublishOnThredds(FileModel theFolderToPublish) {
|
|
|
|
|
|
|
|
this.theFolderToPublish = theFolderToPublish;
|
|
|
|
initLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load vres for logged user.
|
|
|
|
*/
|
|
|
|
private void loadVresForLoggedUser() {
|
|
|
|
|
|
|
|
selectVRE.mask();
|
|
|
|
selectVRE.setLoadingText("Loading VREs...");
|
|
|
|
getButtonById(Dialog.OK).setEnabled(false);
|
|
|
|
AppControllerExplorer.rpcWorkspaceService.getListOfVREsForLoggedUser(new AsyncCallback<List<GcubeVRE>>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(List<GcubeVRE> result) {
|
|
|
|
|
|
|
|
listOfVres = result;
|
|
|
|
setStoreToSelectVre();
|
|
|
|
getButtonById(Dialog.OK).setEnabled(true);
|
|
|
|
selectVRE.unmask();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
|
|
|
|
GWT.log("Error on getting VREs");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the store to select vre.
|
|
|
|
*/
|
|
|
|
private void setStoreToSelectVre() {
|
|
|
|
vreStore.removeAll();
|
|
|
|
vreStore.add(listOfVres);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instantiates a new dialog add folder and smart.
|
|
|
|
*/
|
|
|
|
private void initLayout() {
|
|
|
|
|
|
|
|
FormLayout layout = new FormLayout();
|
2017-09-28 16:47:26 +02:00
|
|
|
layout.setLabelWidth(140);
|
|
|
|
layout.setDefaultWidth(380);
|
2017-09-27 18:38:30 +02:00
|
|
|
setLayout(layout);
|
|
|
|
setButtonAlign(HorizontalAlignment.CENTER);
|
|
|
|
// setHideOnButtonClick(true);
|
|
|
|
// setIcon(IconHelper.createStyle("user"));
|
|
|
|
setHeading("Publish "+Format.ellipse(theFolderToPublish.getName(), 20)+" on Thredds...");
|
|
|
|
setModal(true);
|
|
|
|
// setBodyBorder(true);
|
|
|
|
setBodyStyle("padding: 9px; background: none");
|
|
|
|
setWidth(widthDialog);
|
|
|
|
setResizable(false);
|
|
|
|
setButtons(Dialog.OKCANCEL);
|
|
|
|
|
|
|
|
this.getButtonById(Dialog.OK).setText("Publish");
|
2017-09-28 11:59:49 +02:00
|
|
|
this.getButtonById(Dialog.CANCEL).setText("Close");
|
2017-09-27 18:38:30 +02:00
|
|
|
// this.getButtonById(Dialog.CANCEL).setText("Reset");
|
|
|
|
txtCatalogueName = new TextField<String>();
|
|
|
|
txtCatalogueName.setEmptyText("Type a Name...");
|
|
|
|
txtCatalogueName.setAllowBlank(false);
|
|
|
|
txtCatalogueName.setAutoValidate(true);
|
|
|
|
txtCatalogueName.getMessages().setRegexText(ConstantsExplorer.REGEX_WSFOLDER_NAME_ALERT_MSG);
|
|
|
|
txtCatalogueName.setRegex(ConstantsExplorer.REGEX_TO_WSFOLDER_NAME);
|
|
|
|
txtCatalogueName.setFieldLabel("Catalogue Name *");
|
|
|
|
|
|
|
|
|
|
|
|
triggerFieldMetadataFolderName = new TriggerField<String>();
|
|
|
|
triggerFieldMetadataFolderName.setAllowBlank(true);
|
|
|
|
triggerFieldMetadataFolderName.setReadOnly(true);
|
|
|
|
triggerFieldMetadataFolderName.setAutoValidate(true);
|
|
|
|
triggerFieldMetadataFolderName.setFieldLabel("Metadata Folder");
|
|
|
|
triggerFieldMetadataFolderName.setEmptyText("Browse a Metadata Folder...");
|
|
|
|
triggerFieldMetadataFolderName.addListener(Events.OnClick, new Listener<BaseEvent>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void handleEvent(BaseEvent be) {
|
|
|
|
showWsExplorer();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
selectVRE = new ComboBox<GcubeVRE>();
|
|
|
|
selectVRE.setEmptyText("Select a VRE...");
|
|
|
|
selectVRE.setFieldLabel("Publish in the VRE *");
|
|
|
|
selectVRE.setDisplayField("name");
|
|
|
|
selectVRE.setStore(vreStore);
|
2017-09-28 16:57:10 +02:00
|
|
|
selectVRE.setAllowBlank(false);
|
2017-09-27 18:38:30 +02:00
|
|
|
if(listOfVres==null || listOfVres.isEmpty())
|
|
|
|
loadVresForLoggedUser();
|
|
|
|
else
|
|
|
|
setStoreToSelectVre();
|
|
|
|
//selectVRE.setStore(scopeNameModels);
|
|
|
|
selectVRE.setTypeAhead(true);
|
|
|
|
selectVRE.setEditable(false);
|
|
|
|
selectVRE.setTriggerAction(TriggerAction.ALL);
|
|
|
|
|
|
|
|
|
|
|
|
txtCatalogueName.addKeyListener(new KeyListener() { // KEY ENTER
|
|
|
|
|
|
|
|
public void componentKeyPress(ComponentEvent event) {
|
|
|
|
|
|
|
|
if (event.getKeyCode() == KeyboardEvents.Enter.getEventCode())
|
|
|
|
getButtonById(Dialog.OK).fireEvent(Events.Select);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this.getButtonById(Dialog.CANCEL).addSelectionListener(
|
|
|
|
new SelectionListener<ButtonEvent>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void componentSelected(ButtonEvent ce) {
|
|
|
|
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this.getButtonById(Dialog.OK).addSelectionListener(
|
|
|
|
new SelectionListener<ButtonEvent>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void componentSelected(ButtonEvent ce) {
|
|
|
|
|
|
|
|
if (isValidForm()){
|
|
|
|
hide();
|
|
|
|
|
|
|
|
String metadataFolderId = metadataFolder!=null?metadataFolder.getIdentifier():null;
|
|
|
|
|
|
|
|
GcubeVRE vre = selectVRE.getSelection().get(0);
|
|
|
|
|
|
|
|
AppControllerExplorer.rpcWorkspaceService.publishOnThreddsCatalogue(theFolderToPublish.getIdentifier(), metadataFolderId, vre.getScope(), txtCatalogueName.getValue(), new AsyncCallback<TransferOnThreddsReport>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
|
2017-09-28 11:59:49 +02:00
|
|
|
new MessageBoxAlert("Error", caught.getMessage(), null);
|
2017-09-27 18:38:30 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(TransferOnThreddsReport result) {
|
2017-09-28 11:59:49 +02:00
|
|
|
GWT.log("Publishing on Thredds return: "+result);
|
2017-09-28 15:07:15 +02:00
|
|
|
InfoDisplay.display("On going", "Transferring started correclty...");
|
2017-09-27 18:38:30 +02:00
|
|
|
if(result!=null){
|
2017-09-28 11:59:49 +02:00
|
|
|
pollingStart(result);
|
2017-09-28 12:20:42 +02:00
|
|
|
}else
|
|
|
|
new MessageBoxAlert("Error", "An error occurred during the transferring. Refresh the folder and try again", null);
|
2017-09-27 18:38:30 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
setFocusWidget(txtCatalogueName);
|
|
|
|
add(txtCatalogueName);
|
|
|
|
add(selectVRE);
|
|
|
|
//add(browse);
|
|
|
|
add(triggerFieldMetadataFolderName);
|
|
|
|
Label mandatory = new Label("* mandatory");
|
|
|
|
mandatory.setType(LabelType.INFO);
|
|
|
|
//mandatory.getElement().getStyle().set("#FF0000");
|
|
|
|
add(mandatory);
|
|
|
|
//add(hp);
|
|
|
|
|
|
|
|
this.show();
|
|
|
|
}
|
|
|
|
|
2017-09-28 11:59:49 +02:00
|
|
|
public void showResult(TransferOnThreddsReport result){
|
|
|
|
|
|
|
|
|
|
|
|
if(result.isOnError()){
|
2017-09-28 15:36:37 +02:00
|
|
|
MessageBox.alert("Error", result.getReportMessage(), null);
|
2017-09-28 11:59:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(result.isTransferringReportAvailable()){
|
|
|
|
InfoDisplay.display("Transferring completed", "Refreshing folder content...");
|
|
|
|
FileModel folderTarget = new FileModel(result.getFolderId(), "", true);
|
2017-09-28 16:40:23 +02:00
|
|
|
AppControllerExplorer.getEventBus().fireEvent(new RefreshFolderEvent(folderTarget, false, false, false));
|
2017-09-28 11:59:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void pollingStart(final TransferOnThreddsReport result){
|
|
|
|
|
|
|
|
showResult(result);
|
|
|
|
|
|
|
|
final Timer t = new Timer(){
|
|
|
|
|
|
|
|
public void run() {
|
|
|
|
|
|
|
|
AppControllerExplorer.rpcWorkspaceService.getStatusOfPublishingOnThreddsCatalogue(result.getTransferId(), new AsyncCallback<TransferOnThreddsReport>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
MessageBox.alert("Error", caught.getMessage(), null);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(TransferOnThreddsReport result) {
|
|
|
|
GWT.log("Get status of Publishing on Thredds return: "+result);
|
|
|
|
|
|
|
|
showResult(result);
|
|
|
|
if(result.isOnError() || result.isTransferringReportAvailable()){
|
|
|
|
GWT.log("Cancelling timer for Transferring: "+result);
|
|
|
|
cancelTimer();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
public void cancelTimer(){
|
|
|
|
this.cancel();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
t.scheduleRepeating(2000);
|
|
|
|
|
|
|
|
}
|
2017-09-27 18:38:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if is valid form.
|
|
|
|
*
|
|
|
|
* @return true, if is valid form
|
|
|
|
*/
|
|
|
|
public boolean isValidForm() {
|
|
|
|
|
2017-09-28 16:57:10 +02:00
|
|
|
if (txtCatalogueName.isValid() && txtCatalogueName.getValue() != null && selectVRE.getSelectionLength()>0)
|
2017-09-27 18:38:30 +02:00
|
|
|
return true;
|
2017-09-28 16:57:10 +02:00
|
|
|
|
|
|
|
if(selectVRE.getSelectionLength()==0)
|
|
|
|
selectVRE.forceInvalid("Required");
|
|
|
|
|
2017-09-27 18:38:30 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show ws explorer.
|
|
|
|
*/
|
|
|
|
public void showWsExplorer(){
|
|
|
|
|
|
|
|
final WorkspaceExplorerSelectDialog navigator = new WorkspaceExplorerSelectDialog("Select a folder...", true);
|
|
|
|
|
|
|
|
WorskpaceExplorerSelectNotificationListener listener = new WorskpaceExplorerSelectNotificationListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSelectedItem(Item item) {
|
|
|
|
GWT.log("onSelectedItem: "+item);
|
|
|
|
navigator.hide();
|
|
|
|
triggerFieldMetadataFolderName.setValue(item.getName());
|
|
|
|
metadataFolder = new FileModel(item.getId(), item.getName(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailed(Throwable throwable) {
|
|
|
|
GWT.log("onFailed..");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAborted() {
|
|
|
|
GWT.log("onAborted..");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onNotValidSelection() {
|
|
|
|
GWT.log("onNotValidSelection..");
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
navigator.addWorkspaceExplorerSelectNotificationListener(listener);
|
|
|
|
navigator.show();
|
|
|
|
}
|
|
|
|
}
|