Updated GUI to manage Catalogue Bean and Configurations

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/widgets/ws-thredds-sync-widget@164837 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2018-03-08 16:59:33 +00:00
parent 8957fbad4b
commit f1f1b11294
7 changed files with 500 additions and 131 deletions

View File

@ -3,6 +3,7 @@ package org.gcube.portlets.widgets.wsthreddssync.client.rpc;
import java.util.List; import java.util.List;
import org.gcube.portal.wssynclibrary.shared.ItemNotSynched; import org.gcube.portal.wssynclibrary.shared.ItemNotSynched;
import org.gcube.portal.wssynclibrary.shared.thredds.ThCatalogueBean;
import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus;
import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeVRE; import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeVRE;
import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderConfiguration; import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderConfiguration;
@ -11,17 +12,60 @@ import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescr
import com.google.gwt.user.client.rpc.RemoteService; import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
/** /**
* The client side stub for the RPC service. * The Interface ThreddsWorkspaceSyncService.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Mar 8, 2018
*/ */
@RemoteServiceRelativePath("wsthreddssync") @RemoteServiceRelativePath("wsthreddssync")
public interface ThreddsWorkspaceSyncService extends RemoteService { public interface ThreddsWorkspaceSyncService extends RemoteService {
/**
* Checks if is item synched.
*
* @param folderId the folder id
* @return the ws thredds synch folder descriptor
* @throws ItemNotSynched the item not synched
* @throws Exception the exception
*/
WsThreddsSynchFolderDescriptor isItemSynched(String folderId) throws ItemNotSynched, Exception; WsThreddsSynchFolderDescriptor isItemSynched(String folderId) throws ItemNotSynched, Exception;
/**
* Do sync folder.
*
* @param folderId the folder id
* @param clientConfig the client config
* @return the th sync status
* @throws Exception the exception
*/
ThSyncStatus doSyncFolder(final String folderId, WsThreddsSynchFolderConfiguration clientConfig) throws Exception; ThSyncStatus doSyncFolder(final String folderId, WsThreddsSynchFolderConfiguration clientConfig) throws Exception;
/**
* Monitor sync status.
*
* @param folderId the folder id
* @return the th sync status
* @throws ItemNotSynched the item not synched
* @throws Exception the exception
*/
ThSyncStatus monitorSyncStatus(String folderId) throws ItemNotSynched, Exception; ThSyncStatus monitorSyncStatus(String folderId) throws ItemNotSynched, Exception;
/**
* Gets the list of vr es for logged user.
*
* @return the list of vr es for logged user
* @throws Exception the exception
*/
List<GcubeVRE> getListOfVREsForLoggedUser() throws Exception; List<GcubeVRE> getListOfVREsForLoggedUser() throws Exception;
/**
* Gets the available catalogues for scope.
*
* @param scope the scope
* @return the available catalogues for scope
* @throws Exception the exception
*/
List<ThCatalogueBean> getAvailableCataloguesForScope(String scope) throws Exception;
} }

View File

@ -2,6 +2,7 @@ package org.gcube.portlets.widgets.wsthreddssync.client.rpc;
import java.util.List; import java.util.List;
import org.gcube.portal.wssynclibrary.shared.thredds.ThCatalogueBean;
import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus;
import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeVRE; import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeVRE;
import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderConfiguration; import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderConfiguration;
@ -10,16 +11,31 @@ import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescr
import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.AsyncCallback;
/**
* The Interface ThreddsWorkspaceSyncServiceAsync.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Mar 8, 2018
*/
public interface ThreddsWorkspaceSyncServiceAsync public interface ThreddsWorkspaceSyncServiceAsync
{ {
/** /**
* Utility class to get the RPC Async interface from client-side code * Utility class to get the RPC Async interface from client-side code.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Mar 8, 2018
*/ */
public static final class Util public static final class Util
{ {
private static ThreddsWorkspaceSyncServiceAsync instance; private static ThreddsWorkspaceSyncServiceAsync instance;
/**
* Gets the single instance of Util.
*
* @return single instance of Util
*/
public static final ThreddsWorkspaceSyncServiceAsync getInstance() public static final ThreddsWorkspaceSyncServiceAsync getInstance()
{ {
if ( instance == null ) if ( instance == null )
@ -29,6 +45,9 @@ public interface ThreddsWorkspaceSyncServiceAsync
return instance; return instance;
} }
/**
* Instantiates a new util.
*/
private Util() private Util()
{ {
// Utility class should not be instantiated // Utility class should not be instantiated
@ -36,14 +55,48 @@ public interface ThreddsWorkspaceSyncServiceAsync
} }
/**
* Checks if is item synched.
*
* @param folderId the folder id
* @param callback the callback
*/
void isItemSynched(String folderId, AsyncCallback<WsThreddsSynchFolderDescriptor> callback); void isItemSynched(String folderId, AsyncCallback<WsThreddsSynchFolderDescriptor> callback);
/**
* Do sync folder.
*
* @param folderId the folder id
* @param clientConfig the client config
* @param callback the callback
*/
void doSyncFolder(String folderId, WsThreddsSynchFolderConfiguration clientConfig, AsyncCallback<ThSyncStatus> callback); void doSyncFolder(String folderId, WsThreddsSynchFolderConfiguration clientConfig, AsyncCallback<ThSyncStatus> callback);
/**
* Monitor sync status.
*
* @param folderId the folder id
* @param callback the callback
*/
void monitorSyncStatus(String folderId, AsyncCallback<ThSyncStatus> callback); void monitorSyncStatus(String folderId, AsyncCallback<ThSyncStatus> callback);
/**
* Gets the list of vr es for logged user.
*
* @param callback the callback
* @return the list of vr es for logged user
*/
void getListOfVREsForLoggedUser(AsyncCallback<List<GcubeVRE>> callback); void getListOfVREsForLoggedUser(AsyncCallback<List<GcubeVRE>> callback);
/**
* Gets the available catalogues for scope.
*
* @param scope the scope
* @param callback the callback
* @return the available catalogues for scope
*/
void getAvailableCataloguesForScope(String scope, AsyncCallback<List<ThCatalogueBean>> callback);
} }

View File

@ -6,6 +6,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.gcube.portal.wssynclibrary.shared.thredds.Status; import org.gcube.portal.wssynclibrary.shared.thredds.Status;
import org.gcube.portal.wssynclibrary.shared.thredds.ThCatalogueBean;
import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus;
import org.gcube.portlets.widgets.wsthreddssync.client.WsThreddsWidget; import org.gcube.portlets.widgets.wsthreddssync.client.WsThreddsWidget;
import org.gcube.portlets.widgets.wsthreddssync.client.event.PerformDoSyncEvent; import org.gcube.portlets.widgets.wsthreddssync.client.event.PerformDoSyncEvent;
@ -242,8 +243,10 @@ public class WsThreddsWidgetViewManager {
panelView.closeHandler(); panelView.closeHandler();
WsThreddsSynchFolderConfiguration conf = new WsThreddsSynchFolderConfiguration(); WsThreddsSynchFolderConfiguration conf = new WsThreddsSynchFolderConfiguration();
conf.setFilter(null); conf.setFilter(null);
conf.setRemotePath(getRemotePath());
conf.setCatalogName(getCatalogueName()); ThCatalogueBean catalogueSelected = getSelectedCatalogue();
conf.setRemotePath(catalogueSelected.getPath());
conf.setCatalogName(catalogueSelected.getName());
conf.setTheVRE(getSelectedVRE()); conf.setTheVRE(getSelectedVRE());
WsThreddsWidget.eventBus.fireEvent(new PerformDoSyncEvent(folder, conf)); WsThreddsWidget.eventBus.fireEvent(new PerformDoSyncEvent(folder, conf));
} }

View File

@ -1,21 +1,31 @@
package org.gcube.portlets.widgets.wsthreddssync.client.view.binder; package org.gcube.portlets.widgets.wsthreddssync.client.view.binder;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.gcube.portal.wssynclibrary.shared.thredds.ThCatalogueBean;
import org.gcube.portlets.widgets.wsthreddssync.client.WsThreddsWidget; import org.gcube.portlets.widgets.wsthreddssync.client.WsThreddsWidget;
import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeVRE; import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeVRE;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.ControlGroup; import com.github.gwtbootstrap.client.ui.ControlGroup;
import com.github.gwtbootstrap.client.ui.Fieldset;
import com.github.gwtbootstrap.client.ui.ListBox; import com.github.gwtbootstrap.client.ui.ListBox;
import com.github.gwtbootstrap.client.ui.Pager; import com.github.gwtbootstrap.client.ui.Pager;
import com.github.gwtbootstrap.client.ui.TextBox; import com.github.gwtbootstrap.client.ui.TextBox;
import com.github.gwtbootstrap.client.ui.constants.ControlGroupType; import com.github.gwtbootstrap.client.ui.constants.ControlGroupType;
import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Style.Float;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.DomEvent;
import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField; import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.AsyncCallback;
@ -50,43 +60,67 @@ public abstract class CreateThreddsConfigurationView extends Composite {
/** The pager. */ /** The pager. */
@UiField @UiField
Pager pager; Pager pager;
/** The field course desciption. */
@UiField @UiField
ListBox field_select_vre; ListBox field_select_vre;
@UiField
Button butt_create_new_catalogue;
@UiField
Button butt_add_catalogue;
@UiField
ListBox field_select_catalogue_name;
/** The field catalogue name. */ /** The field catalogue name. */
@UiField @UiField
TextBox field_catalogue_name; TextBox field_catalogue_name;
/** The field folder name. */ /** The field folder name. */
@UiField @UiField
TextBox field_remote_path; TextBox field_folder_name;
/** The cg catalogue name. */ /** The cg catalogue name. */
@UiField @UiField
ControlGroup cg_catalogue_name; ControlGroup cg_catalogue_name;
/** The cg folder name. */
@UiField @UiField
ControlGroup cg_remote_path; ControlGroup cg_folder_name;
/** The cg folder name. */
//@UiField
//ControlGroup cg_remote_path;
@UiField
ControlGroup cg_select_catalogue_name;
@UiField
Fieldset fieldset_add_catalogue_bean;
/** The folder id. */ /** The folder id. */
private String folderId; private String folderId;
/** The map VR es. */ /** The map VR es. */
private Map<String, GcubeVRE> mapVREs = new HashMap<String, GcubeVRE>(); private Map<String, GcubeVRE> mapVREs = new HashMap<String, GcubeVRE>();
private Map<String, List<ThCatalogueBean>> mapCatalogueNames = new HashMap<String, List<ThCatalogueBean>>();
private String currentScope;
/** /**
* Submit handler. * Submit handler.
*/ */
public abstract void submitHandler(); public abstract void submitHandler();
/** /**
* Sets the error. * Sets the error.
* *
@ -94,7 +128,7 @@ public abstract class CreateThreddsConfigurationView extends Composite {
* @param error the error * @param error the error
*/ */
public abstract void setError(boolean visible, String error); public abstract void setError(boolean visible, String error);
/** /**
* Because this class has a default constructor, it can * Because this class has a default constructor, it can
@ -113,44 +147,196 @@ public abstract class CreateThreddsConfigurationView extends Composite {
this.folderId = folderId; this.folderId = folderId;
initWidget(uiBinder.createAndBindUi(this)); initWidget(uiBinder.createAndBindUi(this));
pager.getLeft().setVisible(false); pager.getLeft().setVisible(false);
pager.getRight().addClickHandler(new ClickHandler() { pager.getRight().addClickHandler(new ClickHandler() {
@Override @Override
public void onClick(ClickEvent event) { public void onClick(ClickEvent event) {
setError(false, ""); setError(false, "");
boolean isValid = validateSubmit(); boolean isValid = validateSubmit();
if(isValid) if(isValid)
submitHandler(); submitHandler();
}
});
WsThreddsWidget.wsThreddsSyncService.getListOfVREsForLoggedUser(new AsyncCallback<List<GcubeVRE>>() {
@Override
public void onSuccess(List<GcubeVRE> result) {
for (GcubeVRE gcubeVRE : result) {
mapVREs.put(gcubeVRE.getVreScope(), gcubeVRE);
field_select_vre.addItem(gcubeVRE.getVreScope(), gcubeVRE.getVreName());
}
}
@Override
public void onFailure(Throwable caught) {
// TODO Auto-generated method stub
} }
}); });
cg_catalogue_name.getElement().getStyle().setMarginTop(20, Unit.PX);
field_select_vre.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
String scope = field_select_vre.getSelectedItemText();
GWT.log("Selected VRE: "+scope);
loadCatalogueNamesForScope(scope);
}
});
WsThreddsWidget.wsThreddsSyncService.getListOfVREsForLoggedUser(new AsyncCallback<List<GcubeVRE>>() {
@Override
public void onSuccess(List<GcubeVRE> result) {
for (GcubeVRE gcubeVRE : result) {
mapVREs.put(gcubeVRE.getVreScope(), gcubeVRE);
field_select_vre.addItem(gcubeVRE.getVreScope(), gcubeVRE.getVreName());
}
if(result.size()>0){
field_select_vre.setSelectedValue(result.get(0).getVreName());
//field_select_vre.setSelectedIndex(0);
//field_select_vre.fireEvent(DomEvent.fireNativeEvent(nativeEvent, handlerSource););
DomEvent.fireNativeEvent(Document.get().createChangeEvent(), field_select_vre);
}
}
@Override
public void onFailure(Throwable caught) {
// TODO Auto-generated method stub
}
});
butt_create_new_catalogue.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
fieldset_add_catalogue_bean.setVisible(true);
}
});
butt_add_catalogue.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
if (field_catalogue_name.getValue() == null || field_catalogue_name.getValue().isEmpty()) {
cg_catalogue_name.setType(ControlGroupType.ERROR);
setError(true, "Catalogue Name is required");
return;
}
if(field_folder_name.getValue() == null || field_folder_name.getValue().isEmpty()){
cg_folder_name.setType(ControlGroupType.ERROR);
setError(true, "The Folder Name is required");
return;
}else if(field_folder_name.getValue().startsWith("/")){
cg_folder_name.setType(ControlGroupType.ERROR);
setError(true, "Folder Name must be a relative URL. It does not start with '/'");
return;
}
addCatalogueNameForCurrentScope(field_catalogue_name.getValue(), field_folder_name.getValue());
fieldset_add_catalogue_bean.setVisible(false);
initFieldCatalogueName();
}
});
butt_add_catalogue.getElement().getStyle().setFloat(Float.RIGHT);
butt_add_catalogue.getElement().getStyle().setMarginRight(90, Unit.PX);
} }
/**
* Fill selectable catalogue names.
*
* @param scope the scope
* @param result the result
*/
private void fillSelectableCatalogueNames(String scope, List<ThCatalogueBean> result){
field_select_catalogue_name.clear();
field_select_catalogue_name.setEnabled(true);
if(result!=null && result.size()>0){
mapCatalogueNames.put(scope, result);
for (ThCatalogueBean thCatalogueBean : result) {
field_select_catalogue_name.addItem(thCatalogueBean.getName(), thCatalogueBean.getName());
if(thCatalogueBean.isDefault()){
field_select_catalogue_name.setSelectedValue(thCatalogueBean.getName());
}
}
}
}
/**
* Adds the catalogue name for current scope.
*
* @param catalogueName the catalogue name
* @param folderName the folder name. Can be a relative Path
*/
private void addCatalogueNameForCurrentScope(String catalogueName, String folderName) {
List<ThCatalogueBean> listCtlgs = mapCatalogueNames.get(currentScope);
if(listCtlgs==null){
listCtlgs = new ArrayList<ThCatalogueBean>();
}
listCtlgs.add(new ThCatalogueBean(catalogueName, folderName, true));
fillSelectableCatalogueNames(currentScope, listCtlgs);
}
/**
* Load catalogue names for scope.
*
* @param scope the scope
*/
private void loadCatalogueNamesForScope(String scope){
this.currentScope = scope;
field_select_catalogue_name.setEnabled(false);
initFieldCatalogueName();
List<ThCatalogueBean> listCtlgs = mapCatalogueNames.get(scope);
if(listCtlgs==null){
WsThreddsWidget.wsThreddsSyncService.getAvailableCataloguesForScope(scope, new AsyncCallback<List<ThCatalogueBean>>() {
@Override
public void onFailure(Throwable caught) {
GWT.log("Error: "+caught.getMessage());
field_select_catalogue_name.setEnabled(true);
}
@Override
public void onSuccess(List<ThCatalogueBean> result) {
GWT.log("Fill Catalogue Names: "+result);
fillSelectableCatalogueNames(currentScope, result);
}
});
}else{
fillSelectableCatalogueNames(scope, listCtlgs);
}
}
/**
* Inits the field catalogue name.
*/
private void initFieldCatalogueName() {
field_catalogue_name.setText("");
field_folder_name.setText("");
}
/** /**
* Validate submit. * Validate submit.
* *
@ -158,47 +344,63 @@ public abstract class CreateThreddsConfigurationView extends Composite {
*/ */
protected boolean validateSubmit() { protected boolean validateSubmit() {
cg_catalogue_name.setType(ControlGroupType.NONE); cg_catalogue_name.setType(ControlGroupType.NONE);
cg_remote_path.setType(ControlGroupType.NONE); //cg_remote_path.setType(ControlGroupType.NONE);
if(field_catalogue_name.getValue()==null || field_catalogue_name.getValue().isEmpty()){ // if(field_catalogue_name.getValue()==null || field_catalogue_name.getValue().isEmpty()){
// cg_catalogue_name.setType(ControlGroupType.ERROR);
// setError(true, "Catalogue Name is required");
// return false;
// }
if(field_select_catalogue_name.getSelectedItemText()==null){
cg_catalogue_name.setType(ControlGroupType.ERROR); cg_catalogue_name.setType(ControlGroupType.ERROR);
setError(true, "Catalogue Name is required"); setError(true, "Select a Catalogue Name!!!");
return false; return false;
} }
if(field_remote_path.getValue()==null || field_remote_path.getValue().isEmpty()){ // if(field_remote_path.getValue()==null || field_remote_path.getValue().isEmpty()){
cg_remote_path.setType(ControlGroupType.ERROR); // cg_remote_path.setType(ControlGroupType.ERROR);
setError(true, "Remote Path field is required"); // setError(true, "Remote Path field is required");
return false; // return false;
}else if(field_remote_path.getValue().startsWith("/")){ // }else if(field_remote_path.getValue().startsWith("/")){
cg_remote_path.setType(ControlGroupType.ERROR); // cg_remote_path.setType(ControlGroupType.ERROR);
setError(true, "Remote Path must be a relative URL. It does not start with '/'"); // setError(true, "Remote Path must be a relative URL. It does not start with '/'");
return false; // return false;
} // }
return true; return true;
} }
/** /**
* Gets the remote path. * Gets the selected catalogue.
* *
* @return the remote path * @return the selected catalogue
*/ */
public String getRemotePath() { public ThCatalogueBean getSelectedCatalogue(){
return field_remote_path.getValue();
List<ThCatalogueBean> listCatalogues = mapCatalogueNames.get(currentScope);
String selectedCatalogueName = getCatalogueName();
for (ThCatalogueBean thCatalogueBean : listCatalogues) {
if(thCatalogueBean.getName().compareTo(selectedCatalogueName)==0)
return thCatalogueBean;
}
return null;
} }
/** /**
* Gets the catalogue name. * Gets the catalogue name.
* *
* @return the catalogue name * @return the catalogue name
*/ */
public String getCatalogueName(){ public String getCatalogueName(){
return field_catalogue_name.getValue(); return field_select_catalogue_name.getSelectedItemText();
} }
/** /**
* Gets the unit description. * Gets the unit description.
* *

View File

@ -10,35 +10,52 @@
<g:HTMLPanel ui:field="form_unit_fields"> <g:HTMLPanel ui:field="form_unit_fields">
<b:Form type="HORIZONTAL"> <b:Form type="HORIZONTAL">
<b:Fieldset styleName="{style.noBorder}"> <b:Fieldset styleName="{style.noBorder}">
<b:ControlGroup ui:field="cg_catalogue_name">
<b:ControlLabel for="cl_catalogue_name">Catalogue Name</b:ControlLabel>
<b:Controls>
<b:TextBox placeholder="Type the Catalogue Name..."
b:id="field_catalogue_name" ui:field="field_catalogue_name"></b:TextBox>
</b:Controls>
</b:ControlGroup>
<b:ControlGroup ui:field="cg_unit_description"> <b:ControlGroup ui:field="cg_select_vre">
<b:ControlLabel for="cl_course_description">Publish in the VRE</b:ControlLabel> <b:ControlLabel for="cl_select_vre">Publish in the VRE</b:ControlLabel>
<b:Controls> <b:Controls>
<b:ListBox name="Select a VRE..." <b:ListBox name="Select a VRE..." b:id="field_select_vre"
b:id="field_select_vre" ui:field="field_select_vre"> ui:field="field_select_vre">
</b:ListBox> </b:ListBox>
</b:Controls> </b:Controls>
</b:ControlGroup> </b:ControlGroup>
<b:ControlGroup ui:field="cg_remote_path"> <b:ControlGroup ui:field="cg_select_catalogue_name">
<b:ControlLabel for="cl_remote_path">Remote Path</b:ControlLabel> <b:ControlLabel for="cl_select_catalogue_name">Select Catalogue Name</b:ControlLabel>
<b:Controls> <b:Controls>
<b:TextBox placeholder="Type the Remote Path..." <b:ListBox name="Select a Catalogue Name..." b:id="field_select_catalogue_name"
title="This is the Remote Path" b:id="field_remote_path" ui:field="field_select_catalogue_name">
ui:field="field_remote_path"></b:TextBox> </b:ListBox>
</b:Controls> </b:Controls>
</b:ControlGroup> </b:ControlGroup>
<b:Button ui:field="butt_create_new_catalogue" text="Create New Catalogue"
type="LINK"></b:Button>
<b:Fieldset ui:field="fieldset_add_catalogue_bean" visible="false">
<b:ControlGroup ui:field="cg_catalogue_name">
<b:ControlLabel for="cl_catalogue_name">Catalogue Name</b:ControlLabel>
<b:Controls>
<b:TextBox placeholder="Type the Catalogue Name..."
b:id="field_catalogue_name" ui:field="field_catalogue_name"></b:TextBox>
</b:Controls>
</b:ControlGroup>
<b:ControlGroup ui:field="cg_folder_name">
<b:ControlLabel for="cl_folder_name">Folder Name</b:ControlLabel>
<b:Controls>
<b:TextBox placeholder="Type the Folder Name..."
title="This is the Folder Name" b:id="field_folder_name"
ui:field="field_folder_name"></b:TextBox>
</b:Controls>
</b:ControlGroup>
<b:Button ui:field="butt_add_catalogue">Add Catalogue</b:Button>
</b:Fieldset>
</b:Fieldset> </b:Fieldset>
</b:Form> </b:Form>
</g:HTMLPanel> </g:HTMLPanel>
<b:Pager left="Older" right="Create Configuration and Do Sync" aligned="true" <b:Pager left="Older" right="Create Configuration and Do Sync"
ui:field="pager" /> aligned="true" ui:field="pager" />
</g:HTMLPanel> </g:HTMLPanel>
</ui:UiBinder> </ui:UiBinder>

View File

@ -3,10 +3,13 @@
*/ */
package org.gcube.portlets.widgets.wsthreddssync.server; package org.gcube.portlets.widgets.wsthreddssync.server;
import java.util.List;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portal.wssynclibrary.shared.ItemNotSynched; import org.gcube.portal.wssynclibrary.shared.ItemNotSynched;
import org.gcube.portal.wssynclibrary.shared.thredds.Sync_Status; import org.gcube.portal.wssynclibrary.shared.thredds.Sync_Status;
import org.gcube.portal.wssynclibrary.shared.thredds.ThCatalogueBean;
import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor;
import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus;
import org.gcube.portal.wssynclibrary.shared.thredds.ThSynchFolderConfiguration; import org.gcube.portal.wssynclibrary.shared.thredds.ThSynchFolderConfiguration;
@ -14,9 +17,6 @@ import org.gcube.portal.wssynclibrary.thredds.WorkspaceThreddsSynchronize;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
// TODO: Auto-generated Javadoc
/** /**
* The Class SyncronizeWithThredds. * The Class SyncronizeWithThredds.
* *
@ -31,7 +31,7 @@ public class SyncronizeWithThredds {
/** The workspace thredds synchronize. */ /** The workspace thredds synchronize. */
private WorkspaceThreddsSynchronize workspaceThreddsSynchronize; private WorkspaceThreddsSynchronize workspaceThreddsSynchronize;
/** The Constant sdf. */ /** The Constant sdf. */
//private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss"); //private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss");
@ -46,8 +46,8 @@ public class SyncronizeWithThredds {
public SyncronizeWithThredds() { public SyncronizeWithThredds() {
this.workspaceThreddsSynchronize = WorkspaceThreddsSynchronize.getInstance(); this.workspaceThreddsSynchronize = WorkspaceThreddsSynchronize.getInstance();
} }
/** /**
* Sets the context parameters. * Sets the context parameters.
* *
@ -60,7 +60,7 @@ public class SyncronizeWithThredds {
SecurityTokenProvider.instance.set(userToken); SecurityTokenProvider.instance.set(userToken);
} }
/** /**
* Do sync folder. * Do sync folder.
* *
@ -74,7 +74,7 @@ public class SyncronizeWithThredds {
public synchronized ThSyncStatus doSyncFolder(final String folderId, ThSynchFolderConfiguration thConfig, String scope, String userToken) throws Exception{ public synchronized ThSyncStatus doSyncFolder(final String folderId, ThSynchFolderConfiguration thConfig, String scope, String userToken) throws Exception{
logger.debug("Perfoming doSynFolder on folderId: "+folderId); logger.debug("Perfoming doSynFolder on folderId: "+folderId);
boolean firstSync = false; boolean firstSync = false;
try { try {
setContextParameters(scope, userToken); setContextParameters(scope, userToken);
ThSyncFolderDescriptor folder = workspaceThreddsSynchronize.checkItemSynched(folderId); ThSyncFolderDescriptor folder = workspaceThreddsSynchronize.checkItemSynched(folderId);
@ -85,29 +85,29 @@ public class SyncronizeWithThredds {
logger.error("Error on check item sync: ",e); logger.error("Error on check item sync: ",e);
throw new Exception("Sorry an error occurred during folder publishing, refresh and try again"); throw new Exception("Sorry an error occurred during folder publishing, refresh and try again");
} }
try{ try{
if(firstSync) { if(firstSync) {
if(thConfig==null) if(thConfig==null)
throw new Exception("A valid folder configuration must be provided to perforom synchronization"); throw new Exception("A valid folder configuration must be provided to perforom synchronization");
logger.info("First sync setting synchronized folder configuration: "+thConfig); logger.info("First sync setting synchronized folder configuration: "+thConfig);
workspaceThreddsSynchronize.setSynchronizedFolder(thConfig, folderId); workspaceThreddsSynchronize.setSynchronizedFolder(thConfig, folderId);
} }
logger.info("Calling do sync on folder id: "+folderId); logger.info("Calling do sync on folder id: "+folderId);
return workspaceThreddsSynchronize.doSync(folderId); return workspaceThreddsSynchronize.doSync(folderId);
//SessionUtil.setTransferPublishingOnThredds(httpSession, status); //SessionUtil.setTransferPublishingOnThredds(httpSession, status);
}catch (Exception e) { }catch (Exception e) {
logger.error("Error on do sync: ",e); logger.error("Error on do sync: ",e);
throw new Exception(e.getMessage() +", refresh and try again"); throw new Exception(e.getMessage() +", refresh and try again");
} }
} }
/** /**
* Gets the synched status from item property. * Gets the synched status from item property.
@ -128,7 +128,7 @@ public class SyncronizeWithThredds {
logger.info("The folder id: "+folderId +" is not synched returning null as "+Sync_Status.class.getSimpleName()); logger.info("The folder id: "+folderId +" is not synched returning null as "+Sync_Status.class.getSimpleName());
return null; return null;
} }
}catch (Exception e) { }catch (Exception e) {
logger.error("Error on isItemSynched for id: "+folderId, e); logger.error("Error on isItemSynched for id: "+folderId, e);
throw new Exception("Sorry an error occurred during read sync status from HL properties, try again later"); throw new Exception("Sorry an error occurred during read sync status from HL properties, try again later");
@ -147,12 +147,12 @@ public class SyncronizeWithThredds {
* @throws Exception the exception * @throws Exception the exception
*/ */
public boolean isItemSynched(String folderId, String scope, String username) throws ItemNotSynched, Exception{ public boolean isItemSynched(String folderId, String scope, String username) throws ItemNotSynched, Exception{
Sync_Status value = getSynchedStatusFromItemProperty(folderId, scope, username); Sync_Status value = getSynchedStatusFromItemProperty(folderId, scope, username);
if(value!=null) if(value!=null)
return true; return true;
return false; return false;
} }
@ -172,7 +172,7 @@ public class SyncronizeWithThredds {
setContextParameters(scope, userToken); setContextParameters(scope, userToken);
return workspaceThreddsSynchronize.checkItemSynched(folderId); return workspaceThreddsSynchronize.checkItemSynched(folderId);
} }
/** /**
* Gets the sync status. * Gets the sync status.
* *
@ -184,24 +184,41 @@ public class SyncronizeWithThredds {
* @throws Exception the exception * @throws Exception the exception
*/ */
public ThSyncStatus monitorSyncStatus(String itemId, String scope, String userToken) throws ItemNotSynched, Exception{ public ThSyncStatus monitorSyncStatus(String itemId, String scope, String userToken) throws ItemNotSynched, Exception{
setContextParameters(scope, userToken); setContextParameters(scope, userToken);
return workspaceThreddsSynchronize.monitorSyncStatus(itemId); return workspaceThreddsSynchronize.monitorSyncStatus(itemId);
} }
/** /**
* Register callback for id. * Register callback for id.
* *
* @param folderId the folder id * @param folderId the folder id
* @param scope the scope * @param scope the scope
* @param userToken the user token * @param userToken the user token
* @throws Exception * @throws Exception the exception
*/ */
public void registerCallbackForId(String folderId, String scope, String userToken) throws Exception { public void registerCallbackForId(String folderId, String scope, String userToken) throws Exception {
setContextParameters(scope, userToken); setContextParameters(scope, userToken);
workspaceThreddsSynchronize.registerCallbackForId(folderId); workspaceThreddsSynchronize.registerCallbackForId(folderId);
} }
/**
* Gets the available catalogues by token.
*
* @param scope the scope
* @param userToken the user token
* @param targetToken the target token
* @return
* @return the available catalogues by token
* @throws Exception
*/
public List<ThCatalogueBean> getAvailableCataloguesByToken(String scope, String userToken, String targetToken) throws Exception {
setContextParameters(scope, userToken);
return workspaceThreddsSynchronize.getAvailableCataloguesByToken(targetToken);
}
} }

View File

@ -6,6 +6,7 @@ import java.util.List;
import org.gcube.common.portal.PortalContext; import org.gcube.common.portal.PortalContext;
import org.gcube.portal.wssynclibrary.shared.ItemNotSynched; import org.gcube.portal.wssynclibrary.shared.ItemNotSynched;
import org.gcube.portal.wssynclibrary.shared.thredds.Sync_Status; import org.gcube.portal.wssynclibrary.shared.thredds.Sync_Status;
import org.gcube.portal.wssynclibrary.shared.thredds.ThCatalogueBean;
import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor;
import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus; import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus;
import org.gcube.portal.wssynclibrary.shared.thredds.ThSynchFolderConfiguration; import org.gcube.portal.wssynclibrary.shared.thredds.ThSynchFolderConfiguration;
@ -35,10 +36,10 @@ import com.liferay.portal.service.UserLocalServiceUtil;
*/ */
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implements ThreddsWorkspaceSyncService { public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implements ThreddsWorkspaceSyncService {
/** The logger. */ /** The logger. */
private static Logger logger = LoggerFactory.getLogger(ThreddsWorkspaceSyncServiceImpl.class); private static Logger logger = LoggerFactory.getLogger(ThreddsWorkspaceSyncServiceImpl.class);
/** The sync thredds. */ /** The sync thredds. */
private SyncronizeWithThredds syncThredds = null; private SyncronizeWithThredds syncThredds = null;
@ -48,14 +49,14 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
* @return the sync service * @return the sync service
*/ */
public synchronized SyncronizeWithThredds getSyncService() { public synchronized SyncronizeWithThredds getSyncService() {
if(syncThredds==null) if(syncThredds==null)
syncThredds = new SyncronizeWithThredds(); syncThredds = new SyncronizeWithThredds();
return syncThredds; return syncThredds;
} }
/** /**
* Checks if is within portal. * Checks if is within portal.
* *
@ -71,8 +72,8 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
return false; return false;
} }
} }
/** /**
* Do sync folder. * Do sync folder.
@ -104,19 +105,51 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
config = BeanConverter.toThSynchFolderConfiguration(clientConfig, targetScopeUserToken); config = BeanConverter.toThSynchFolderConfiguration(clientConfig, targetScopeUserToken);
logger.debug("Creating server config "+config); logger.debug("Creating server config "+config);
} }
logger.info("Calling doSyncFolder on folderId: "+folderId +", config: "+config); logger.info("Calling doSyncFolder on folderId: "+folderId +", config: "+config);
String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest()); String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest());
String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername()); String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername());
ThSyncStatus status = getSyncService().doSyncFolder(folderId, config, wsScope, wsUserToken); ThSyncStatus status = getSyncService().doSyncFolder(folderId, config, wsScope, wsUserToken);
logger.debug("Returning for folderId "+folderId+" the syncStatus: "+status); logger.debug("Returning for folderId "+folderId+" the syncStatus: "+status);
return status; return status;
}catch (Exception e) { }catch (Exception e) {
logger.error("Do sync Folder error: ",e); logger.error("Do sync Folder error: ",e);
throw new Exception("Sorry, an error occurred during synchonization phase, try again later"); throw new Exception("Sorry, an error occurred during synchonization phase, try again later");
} }
} }
/**
* Gets the available catalogues for scope.
*
* @param scope the scope
* @return the available catalogues for scope
* @throws Exception the exception
*/
@Override
public List<ThCatalogueBean> getAvailableCataloguesForScope(String scope) throws Exception {
if(scope==null)
throw new Exception("Invalid scope null");
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest());
String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername());
String targetScopeUserToken = PortalContext.getConfiguration().getCurrentUserToken(scope, user.getUsername());
List<ThCatalogueBean> listCtlgs = getSyncService().getAvailableCataloguesByToken(scope, wsUserToken, targetScopeUserToken);
logger.debug("Retuning "+listCtlgs.size()+" Catalogues for scope: "+scope);
if(logger.isDebugEnabled()){
for (ThCatalogueBean thCatalogueBean : listCtlgs) {
logger.debug(thCatalogueBean.toString());
}
}
return listCtlgs;
}
/** /**
* Gets the list of VR es for logged user. * Gets the list of VR es for logged user.
@ -163,7 +196,7 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
return listOfVres; return listOfVres;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -171,15 +204,15 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
*/ */
@Override @Override
public WsThreddsSynchFolderDescriptor isItemSynched(String folderId) throws Exception{ public WsThreddsSynchFolderDescriptor isItemSynched(String folderId) throws Exception{
logger.debug("Performing isItemSynched for foldeId: "+folderId); logger.debug("Performing isItemSynched for foldeId: "+folderId);
try { try {
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest()); String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest());
Sync_Status theStatus = getSyncService().getSynchedStatusFromItemProperty(folderId, wsScope, user.getUsername()); Sync_Status theStatus = getSyncService().getSynchedStatusFromItemProperty(folderId, wsScope, user.getUsername());
if(theStatus!=null) { if(theStatus!=null) {
logger.info("Folder id: "+folderId+" is synched"); logger.info("Folder id: "+folderId+" is synched");
String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername()); String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername());
@ -188,10 +221,10 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
logger.debug("IsItemSynched for id: "+folderId +" returning: "+toWsThreddFolder); logger.debug("IsItemSynched for id: "+folderId +" returning: "+toWsThreddFolder);
return toWsThreddFolder; return toWsThreddFolder;
} }
logger.info("Folder id: "+folderId+" is not synched, returning null descriptor"); logger.info("Folder id: "+folderId+" is not synched, returning null descriptor");
return null; return null;
} catch (ItemNotSynched e) { } catch (ItemNotSynched e) {
logger.info("The folderId: "+folderId +" is not synched, returning null FolderDescriptor"); logger.info("The folderId: "+folderId +" is not synched, returning null FolderDescriptor");
return null; return null;
@ -200,8 +233,8 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
throw new Exception(e); throw new Exception(e);
} }
} }
/** /**
* Register callback for id. * Register callback for id.
* *
@ -215,7 +248,7 @@ public class ThreddsWorkspaceSyncServiceImpl extends RemoteServiceServlet implem
getSyncService().registerCallbackForId(folderId, wsScope, wsUserToken); getSyncService().registerCallbackForId(folderId, wsScope, wsUserToken);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.gcube.portlets.widgets.wsthreddssync.client.rpc.ThreddsWorkspaceSyncService#monitorSyncStatus(java.lang.String) * @see org.gcube.portlets.widgets.wsthreddssync.client.rpc.ThreddsWorkspaceSyncService#monitorSyncStatus(java.lang.String)
*/ */