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
pull/1/head
Francesco Mangiacrapa 6 years ago
parent 8957fbad4b
commit f1f1b11294

@ -3,6 +3,7 @@ package org.gcube.portlets.widgets.wsthreddssync.client.rpc;
import java.util.List;
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.portlets.widgets.wsthreddssync.shared.GcubeVRE;
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.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")
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;
/**
* 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;
/**
* 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;
/**
* 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;
/**
* 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;
}

@ -2,6 +2,7 @@ package org.gcube.portlets.widgets.wsthreddssync.client.rpc;
import java.util.List;
import org.gcube.portal.wssynclibrary.shared.thredds.ThCatalogueBean;
import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus;
import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeVRE;
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.user.client.rpc.AsyncCallback;
/**
* The Interface ThreddsWorkspaceSyncServiceAsync.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Mar 8, 2018
*/
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;
/**
* Gets the single instance of Util.
*
* @return single instance of Util
*/
public static final ThreddsWorkspaceSyncServiceAsync getInstance()
{
if ( instance == null )
@ -29,6 +45,9 @@ public interface ThreddsWorkspaceSyncServiceAsync
return instance;
}
/**
* Instantiates a new util.
*/
private Util()
{
// 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);
/**
* 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);
/**
* Monitor sync status.
*
* @param folderId the folder id
* @param callback the 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);
/**
* 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);
}

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

@ -1,21 +1,31 @@
package org.gcube.portlets.widgets.wsthreddssync.client.view.binder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
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.shared.GcubeVRE;
import com.github.gwtbootstrap.client.ui.Button;
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.Pager;
import com.github.gwtbootstrap.client.ui.TextBox;
import com.github.gwtbootstrap.client.ui.constants.ControlGroupType;
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.ClickHandler;
import com.google.gwt.event.dom.client.DomEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.rpc.AsyncCallback;
@ -50,43 +60,67 @@ public abstract class CreateThreddsConfigurationView extends Composite {
/** The pager. */
@UiField
Pager pager;
/** The field course desciption. */
@UiField
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. */
@UiField
TextBox field_catalogue_name;
/** The field folder name. */
@UiField
TextBox field_remote_path;
TextBox field_folder_name;
/** The cg catalogue name. */
@UiField
ControlGroup cg_catalogue_name;
@UiField
ControlGroup cg_folder_name;
/** The cg folder name. */
//@UiField
//ControlGroup cg_remote_path;
@UiField
ControlGroup cg_select_catalogue_name;
@UiField
ControlGroup cg_remote_path;
Fieldset fieldset_add_catalogue_bean;
/** The folder id. */
private String folderId;
/** The map VR es. */
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.
*/
public abstract void submitHandler();
/**
* Sets the error.
*
@ -94,7 +128,7 @@ public abstract class CreateThreddsConfigurationView extends Composite {
* @param error the error
*/
public abstract void setError(boolean visible, String error);
/**
* Because this class has a default constructor, it can
@ -113,44 +147,196 @@ public abstract class CreateThreddsConfigurationView extends Composite {
this.folderId = folderId;
initWidget(uiBinder.createAndBindUi(this));
pager.getLeft().setVisible(false);
pager.getRight().addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
setError(false, "");
boolean isValid = validateSubmit();
if(isValid)
submitHandler();
}
});
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.
*
@ -158,47 +344,63 @@ public abstract class CreateThreddsConfigurationView extends Composite {
*/
protected boolean validateSubmit() {
cg_catalogue_name.setType(ControlGroupType.NONE);
cg_remote_path.setType(ControlGroupType.NONE);
if(field_catalogue_name.getValue()==null || field_catalogue_name.getValue().isEmpty()){
//cg_remote_path.setType(ControlGroupType.NONE);
// 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);
setError(true, "Catalogue Name is required");
return false;
}
if(field_remote_path.getValue()==null || field_remote_path.getValue().isEmpty()){
cg_remote_path.setType(ControlGroupType.ERROR);
setError(true, "Remote Path field is required");
return false;
}else if(field_remote_path.getValue().startsWith("/")){
cg_remote_path.setType(ControlGroupType.ERROR);
setError(true, "Remote Path must be a relative URL. It does not start with '/'");
setError(true, "Select a Catalogue Name!!!");
return false;
}
// if(field_remote_path.getValue()==null || field_remote_path.getValue().isEmpty()){
// cg_remote_path.setType(ControlGroupType.ERROR);
// setError(true, "Remote Path field is required");
// return false;
// }else if(field_remote_path.getValue().startsWith("/")){
// cg_remote_path.setType(ControlGroupType.ERROR);
// setError(true, "Remote Path must be a relative URL. It does not start with '/'");
// return false;
// }
return true;
}
/**
* Gets the remote path.
* Gets the selected catalogue.
*
* @return the remote path
* @return the selected catalogue
*/
public String getRemotePath() {
return field_remote_path.getValue();
public ThCatalogueBean getSelectedCatalogue(){
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.
*
* @return the catalogue name
*/
public String getCatalogueName(){
return field_catalogue_name.getValue();
return field_select_catalogue_name.getSelectedItemText();
}
/**
* Gets the unit description.
*

@ -10,35 +10,52 @@
<g:HTMLPanel ui:field="form_unit_fields">
<b:Form type="HORIZONTAL">
<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:ControlLabel for="cl_course_description">Publish in the VRE</b:ControlLabel>
<b:ControlGroup ui:field="cg_select_vre">
<b:ControlLabel for="cl_select_vre">Publish in the VRE</b:ControlLabel>
<b:Controls>
<b:ListBox name="Select a VRE..."
b:id="field_select_vre" ui:field="field_select_vre">
<b:ListBox name="Select a VRE..." b:id="field_select_vre"
ui:field="field_select_vre">
</b:ListBox>
</b:Controls>
</b:ControlGroup>
<b:ControlGroup ui:field="cg_remote_path">
<b:ControlLabel for="cl_remote_path">Remote Path</b:ControlLabel>
<b:ControlGroup ui:field="cg_select_catalogue_name">
<b:ControlLabel for="cl_select_catalogue_name">Select Catalogue Name</b:ControlLabel>
<b:Controls>
<b:TextBox placeholder="Type the Remote Path..."
title="This is the Remote Path" b:id="field_remote_path"
ui:field="field_remote_path"></b:TextBox>
<b:ListBox name="Select a Catalogue Name..." b:id="field_select_catalogue_name"
ui:field="field_select_catalogue_name">
</b:ListBox>
</b:Controls>
</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:Form>
</g:HTMLPanel>
<b:Pager left="Older" right="Create Configuration and Do Sync" aligned="true"
ui:field="pager" />
<b:Pager left="Older" right="Create Configuration and Do Sync"
aligned="true" ui:field="pager" />
</g:HTMLPanel>
</ui:UiBinder>

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

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

Loading…
Cancel
Save