From 7488d32cd1c936d7a7a3c674820bcd207d0d4e48 Mon Sep 17 00:00:00 2001 From: Francesco Mangiacrapa Date: Fri, 2 Mar 2018 16:03:57 +0000 Subject: [PATCH] Initial import from private svn git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/widgets/ws-thredds-sync-widget@164683 82a268e6-3cf1-43bd-a215-b396298e98cf --- .classpath | 32 ++ .project | 48 +++ .settings/.jsdtscope | 13 + .../com.gwtplugins.gdt.eclipse.core.prefs | 4 + .settings/org.eclipse.core.resources.prefs | 6 + .settings/org.eclipse.jdt.core.prefs | 8 + .settings/org.eclipse.m2e.core.prefs | 4 + .settings/org.eclipse.wst.common.component | 10 + ...se.wst.common.project.facet.core.prefs.xml | 7 + ....eclipse.wst.common.project.facet.core.xml | 9 + ...rg.eclipse.wst.jsdt.ui.superType.container | 1 + .../org.eclipse.wst.jsdt.ui.superType.name | 1 + .settings/org.eclipse.wst.validation.prefs | 2 + distro/LICENSE | 1 + distro/README | 60 +++ distro/changelog.xml | 6 + distro/descriptor.xml | 32 ++ distro/profile.xml | 25 ++ pom.xml | 232 +++++++++++ .../wsthreddssync/WsThreddsWidget.gwt.xml | 28 ++ .../client/WsThreddsSyncWidget.java | 35 ++ .../wsthreddssync/client/WsThreddsWidget.java | 164 ++++++++ .../client/dialog/DialogConfirm.java | 150 ++++++++ .../client/dialog/DialogResult.java | 81 ++++ .../client/event/PerformDoSyncEvent.java | 67 ++++ .../event/PerformDoSyncEventHandler.java | 22 ++ .../event/ShowMonitorSyncStatusEvent.java | 54 +++ .../ShowMonitorSyncStatusEventHandler.java | 23 ++ .../wsthreddssync/client/resource/Icons.java | 31 ++ .../wsthreddssync/client/resource/loading.gif | Bin 0 -> 2533 bytes .../rpc/ThreddsWorkspaceSyncService.java | 27 ++ .../rpc/ThreddsWorkspaceSyncServiceAsync.java | 49 +++ .../wsthreddssync/client/view/FormatUtil.java | 40 ++ .../wsthreddssync/client/view/LoaderIcon.java | 61 +++ .../view/WsThreddsWidgetViewManager.java | 359 ++++++++++++++++++ .../view/binder/AbstractViewDialogBox.java | 157 ++++++++ .../view/binder/AbstractViewDialogBox.ui.xml | 14 + .../CreateThreddsConfigurationView.java | 216 +++++++++++ .../CreateThreddsConfigurationView.ui.xml | 44 +++ .../binder/MonitorFolderSyncStatusView.java | 274 +++++++++++++ .../binder/MonitorFolderSyncStatusView.ui.xml | 98 +++++ .../binder/ShowThreddsFolderInfoView.java | 320 ++++++++++++++++ .../binder/ShowThreddsFolderInfoView.ui.xml | 71 ++++ .../wsthreddssync/public/WsThreddsWidget.css | 8 + .../wsthreddssync/server/BeanConverter.java | 85 +++++ .../wsthreddssync/server/SessionUtil.java | 91 +++++ .../server/SyncronizeWithThredds.java | 207 ++++++++++ .../ThreddsWorkspaceSyncServiceImpl.java | 231 +++++++++++ .../widgets/wsthreddssync/server/WsUtil.java | 85 +++++ .../wsthreddssync/shared/FieldVerifier.java | 42 ++ .../wsthreddssync/shared/GcubeVRE.java | 111 ++++++ .../shared/TransferOnThreddsReport.java | 201 ++++++++++ .../shared/TransferToThreddsProperty.java | 232 +++++++++++ .../wsthreddssync/shared/WsFolder.java | 63 +++ .../WsThreddsSynchFolderConfiguration.java | 151 ++++++++ .../WsThreddsSynchFolderDescriptor.java | 122 ++++++ .../wsthreddssync/WsThreddsWidget.gwt.xml | 28 ++ src/main/webapp/WEB-INF/web.xml | 24 ++ src/main/webapp/WsThreddsWidget.css | 44 +++ src/main/webapp/WsThreddsWidget.html | 63 +++ .../wsthreddssync/TestWsThreddsEngine.java | 131 +++++++ .../wsthreddssync/TestWsThreddsQuery.java | 49 +++ .../WsThreddsWidgetJUnit.gwt.xml | 9 + 63 files changed, 4863 insertions(+) create mode 100644 .classpath create mode 100644 .project create mode 100644 .settings/.jsdtscope create mode 100644 .settings/com.gwtplugins.gdt.eclipse.core.prefs create mode 100644 .settings/org.eclipse.core.resources.prefs create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 .settings/org.eclipse.m2e.core.prefs create mode 100644 .settings/org.eclipse.wst.common.component create mode 100644 .settings/org.eclipse.wst.common.project.facet.core.prefs.xml create mode 100644 .settings/org.eclipse.wst.common.project.facet.core.xml create mode 100644 .settings/org.eclipse.wst.jsdt.ui.superType.container create mode 100644 .settings/org.eclipse.wst.jsdt.ui.superType.name create mode 100644 .settings/org.eclipse.wst.validation.prefs create mode 100644 distro/LICENSE create mode 100644 distro/README create mode 100644 distro/changelog.xml create mode 100644 distro/descriptor.xml create mode 100644 distro/profile.xml create mode 100644 pom.xml create mode 100644 src/main/java/org/gcube/portlets/widgets/wsthreddssync/WsThreddsWidget.gwt.xml create mode 100644 src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/WsThreddsSyncWidget.java create mode 100644 src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/WsThreddsWidget.java create mode 100644 src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/dialog/DialogConfirm.java create mode 100644 src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/dialog/DialogResult.java create mode 100644 src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/event/PerformDoSyncEvent.java create mode 100644 src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/event/PerformDoSyncEventHandler.java create mode 100644 src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/event/ShowMonitorSyncStatusEvent.java create mode 100644 src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/event/ShowMonitorSyncStatusEventHandler.java create mode 100644 src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/resource/Icons.java create mode 100644 src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/resource/loading.gif create mode 100644 src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/rpc/ThreddsWorkspaceSyncService.java create mode 100644 src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/rpc/ThreddsWorkspaceSyncServiceAsync.java create mode 100644 src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/FormatUtil.java create mode 100644 src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/LoaderIcon.java create mode 100644 src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/WsThreddsWidgetViewManager.java create mode 100644 src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/AbstractViewDialogBox.java create mode 100644 src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/AbstractViewDialogBox.ui.xml create mode 100644 src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/CreateThreddsConfigurationView.java create mode 100644 src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/CreateThreddsConfigurationView.ui.xml create mode 100644 src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/MonitorFolderSyncStatusView.java create mode 100644 src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/MonitorFolderSyncStatusView.ui.xml create mode 100644 src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/ShowThreddsFolderInfoView.java create mode 100644 src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/ShowThreddsFolderInfoView.ui.xml create mode 100644 src/main/java/org/gcube/portlets/widgets/wsthreddssync/public/WsThreddsWidget.css create mode 100644 src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/BeanConverter.java create mode 100644 src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SessionUtil.java create mode 100644 src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java create mode 100644 src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java create mode 100644 src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/WsUtil.java create mode 100644 src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/FieldVerifier.java create mode 100644 src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/GcubeVRE.java create mode 100644 src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/TransferOnThreddsReport.java create mode 100644 src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/TransferToThreddsProperty.java create mode 100644 src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/WsFolder.java create mode 100644 src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/WsThreddsSynchFolderConfiguration.java create mode 100644 src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/WsThreddsSynchFolderDescriptor.java create mode 100644 src/main/resources/org/gcube/portlets/widgets/wsthreddssync/WsThreddsWidget.gwt.xml create mode 100644 src/main/webapp/WEB-INF/web.xml create mode 100644 src/main/webapp/WsThreddsWidget.css create mode 100644 src/main/webapp/WsThreddsWidget.html create mode 100644 src/test/java/org/gcube/portlets/widgets/wsthreddssync/TestWsThreddsEngine.java create mode 100644 src/test/java/org/gcube/portlets/widgets/wsthreddssync/TestWsThreddsQuery.java create mode 100644 src/test/resources/org/gcube/portlets/widgets/wsthreddssync/WsThreddsWidgetJUnit.gwt.xml diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..3f8870e --- /dev/null +++ b/.classpath @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..a4aeae3 --- /dev/null +++ b/.project @@ -0,0 +1,48 @@ + + + ws-thredds-sync-widget + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + com.gwtplugins.gdt.eclipse.core.webAppProjectValidator + + + + + com.gwtplugins.gwt.eclipse.core.gwtProjectValidator + + + + + org.eclipse.wst.validation.validationbuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + org.eclipse.wst.common.project.facet.core.nature + com.gwtplugins.gwt.eclipse.core.gwtNature + org.eclipse.wst.jsdt.core.jsNature + + diff --git a/.settings/.jsdtscope b/.settings/.jsdtscope new file mode 100644 index 0000000..f179e11 --- /dev/null +++ b/.settings/.jsdtscope @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/.settings/com.gwtplugins.gdt.eclipse.core.prefs b/.settings/com.gwtplugins.gdt.eclipse.core.prefs new file mode 100644 index 0000000..6a51359 --- /dev/null +++ b/.settings/com.gwtplugins.gdt.eclipse.core.prefs @@ -0,0 +1,4 @@ +eclipse.preferences.version=1 +lastWarOutDir=/home/francesco-mangiacrapa/eclipse-oxygen/ws-thredds-sync-widget/target/ws-thredds-sync-widget-0.0.1-SNAPSHOT +warSrcDir=src/main/webapp +warSrcDirIsOutput=false diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..29abf99 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,6 @@ +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding//src/main/resources=UTF-8 +encoding//src/test/java=UTF-8 +encoding//src/test/resources=UTF-8 +encoding/=UTF-8 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..6e80039 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component new file mode 100644 index 0000000..26d34c5 --- /dev/null +++ b/.settings/org.eclipse.wst.common.component @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml b/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml new file mode 100644 index 0000000..cc81385 --- /dev/null +++ b/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..8387216 --- /dev/null +++ b/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/.settings/org.eclipse.wst.jsdt.ui.superType.container b/.settings/org.eclipse.wst.jsdt.ui.superType.container new file mode 100644 index 0000000..3bd5d0a --- /dev/null +++ b/.settings/org.eclipse.wst.jsdt.ui.superType.container @@ -0,0 +1 @@ +org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/.settings/org.eclipse.wst.jsdt.ui.superType.name b/.settings/org.eclipse.wst.jsdt.ui.superType.name new file mode 100644 index 0000000..05bd71b --- /dev/null +++ b/.settings/org.eclipse.wst.jsdt.ui.superType.name @@ -0,0 +1 @@ +Window \ No newline at end of file diff --git a/.settings/org.eclipse.wst.validation.prefs b/.settings/org.eclipse.wst.validation.prefs new file mode 100644 index 0000000..04cad8c --- /dev/null +++ b/.settings/org.eclipse.wst.validation.prefs @@ -0,0 +1,2 @@ +disabled=06target +eclipse.preferences.version=1 diff --git a/distro/LICENSE b/distro/LICENSE new file mode 100644 index 0000000..2d9616a --- /dev/null +++ b/distro/LICENSE @@ -0,0 +1 @@ +${gcube.license} \ No newline at end of file diff --git a/distro/README b/distro/README new file mode 100644 index 0000000..470bcbf --- /dev/null +++ b/distro/README @@ -0,0 +1,60 @@ +The gCube System - ${name} +-------------------------------------------------- + +${description} + + +${gcube.description} + +${gcube.funding} + + +Version +-------------------------------------------------- + +${version} (${buildDate}) + +Please see the file named "changelog.xml" in this directory for the release notes. + + +Authors +-------------------------------------------------- + +* Francesco Mangiacrapa (francesco.mangiacrapa-AT-isti.cnr.it), Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo" - CNR, Pisa (Italy). + +Maintainers +----------- + +* Francesco Mangiacrapa (francesco.mangiacrapa-AT-isti.cnr.it), Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo" - CNR, Pisa (Italy). + +Download information +-------------------------------------------------- + +Source code is available from SVN: + ${scm.url} + +Binaries can be downloaded from the gCube website: + ${gcube.website} + + +Installation +-------------------------------------------------- + + +Documentation +-------------------------------------------------- + +Documentation is available on-line in the gCube Wiki: + ${gcube.wikiRoot}/gcube/GCube_Widgets_Store + +Support +-------------------------------------------------- + +Bugs and support requests can be reported in the gCube issue tracking tool: + ${gcube.issueTracking} + + +Licensing +-------------------------------------------------- + +This software is licensed under the terms you may find in the file named "LICENSE" in this directory. \ No newline at end of file diff --git a/distro/changelog.xml b/distro/changelog.xml new file mode 100644 index 0000000..cefdaba --- /dev/null +++ b/distro/changelog.xml @@ -0,0 +1,6 @@ + + + First Release + + diff --git a/distro/descriptor.xml b/distro/descriptor.xml new file mode 100644 index 0000000..c597cd2 --- /dev/null +++ b/distro/descriptor.xml @@ -0,0 +1,32 @@ + + servicearchive + + tar.gz + + / + + + ${distroDirectory} + / + true + + README + LICENSE + changelog.xml + profile.xml + + 755 + true + + + + + target/${build.finalName}.${project.packaging} + /${artifactId} + + + + diff --git a/distro/profile.xml b/distro/profile.xml new file mode 100644 index 0000000..a8e8deb --- /dev/null +++ b/distro/profile.xml @@ -0,0 +1,25 @@ + + + + Library + + ${description} + PortletsWidgets + ${artifactId} + 1.0.0 + + + ${artifactId} + ${version} + + ${groupId} + ${artifactId} + ${version} + + + ${build.finalName}.jar + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..cf6d384 --- /dev/null +++ b/pom.xml @@ -0,0 +1,232 @@ + + + 4.0.0 + + maven-parent + org.gcube.tools + 1.0.0 + + + + org.gcube.portlets.widgets + ws-thredds-sync-widget + jar + 0.0.1-SNAPSHOT + ws-thredds-sync-widget + + gCube ws-thredds-sync-widget is a widget to use and interact with ws-thredds facility in order to syncronize the Workspace folders with Thredds Reporitory folders + + + + scm:svn:http://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/${project.artifactId} + scm:https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/${project.artifactId} + http://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/${project.artifactId} + + + + + 2.7.0 + distro + + 1.8 + 1.8 + + + UTF-8 + UTF-8 + + + + + + org.gcube.distribution + maven-portal-bom + LATEST + pom + import + + + + + + + com.google.gwt + gwt-user + ${gwtVersion} + provided + + + com.github.gwtbootstrap + gwt-bootstrap + + + + + org.gcube.common.portal + portal-manager + provided + + + + com.liferay.portal + portal-service + provided + + + + + org.gcube.dvos + usermanagement-core + provided + + + + org.gcube.portal + ws-synchronized-module-library + [0.0.1-SNAPSHOT, 1.0.0-SNAPSHOT) + + + + + + + + + + + org.gcube.common + authorization-client + [2.0.0-SNAPSHOT, 3-0-0-SNAPSHOT) + + + + + + + org.slf4j + slf4j-log4j12 + + + org.slf4j + slf4j-api + + + + junit + junit + 4.11 + test + + + + + + + src/main/java + + **/*.* + + + + + + maven-compiler-plugin + + ${maven.compiler.source} + ${maven.compiler.target} + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.2 + + + + test-jar + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.12 + + true + + + + org.apache.maven.plugins + maven-resources-plugin + 2.5 + + + copy-profile + install + + copy-resources + + + target + + + ${distroDirectory} + true + + profile.xml + + + + + + + + + + org.apache.maven.plugins + maven-assembly-plugin + 2.2 + + + ${distroDirectory}/descriptor.xml + + + + fully.qualified.MainClass + + + + + + servicearchive + install + + single + + + + + + + + org.codehaus.mojo + gwt-maven-plugin + ${gwtVersion} + + + + + + + + + + + + + + diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/WsThreddsWidget.gwt.xml b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/WsThreddsWidget.gwt.xml new file mode 100644 index 0000000..d7d2257 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/WsThreddsWidget.gwt.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/WsThreddsSyncWidget.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/WsThreddsSyncWidget.java new file mode 100644 index 0000000..fb1c67a --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/WsThreddsSyncWidget.java @@ -0,0 +1,35 @@ +package org.gcube.portlets.widgets.wsthreddssync.client; +//package org.gcube.portlets.widgets.wsthreddssync.client; +// +//import org.gcube.portlets.widgets.wsthreddssync.client.rpc.ThreddsWorkspaceSyncService; +//import org.gcube.portlets.widgets.wsthreddssync.client.rpc.ThreddsWorkspaceSyncServiceAsync; +// +//import com.google.gwt.core.client.EntryPoint; +//import com.google.gwt.core.client.GWT; +// +//// TODO: Auto-generated Javadoc +///** +// * Entry point classes define onModuleLoad(). +// * +// * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it +// * Feb 14, 2018 +// */ +//public class WsThreddsSyncWidget implements EntryPoint { +// /** +// * The message displayed to the user when the server cannot be reached or +// * returns an error. +// */ +// private static final String SERVER_ERROR = "An error occurred while " +// + "attempting to contact the server. Please check your network " +// + "connection and try again."; +// +// /** The ws thredds sync service. */ +// private final ThreddsWorkspaceSyncServiceAsync wsThreddsSyncService = GWT.create(ThreddsWorkspaceSyncService.class); +// +// /** +// * This is the entry point method. +// */ +// public void onModuleLoad() { +// +// } +//} diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/WsThreddsWidget.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/WsThreddsWidget.java new file mode 100644 index 0000000..70c382f --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/WsThreddsWidget.java @@ -0,0 +1,164 @@ +package org.gcube.portlets.widgets.wsthreddssync.client; + +import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus; +import org.gcube.portlets.widgets.wsthreddssync.client.event.PerformDoSyncEvent; +import org.gcube.portlets.widgets.wsthreddssync.client.event.PerformDoSyncEventHandler; +import org.gcube.portlets.widgets.wsthreddssync.client.event.ShowMonitorSyncStatusEvent; +import org.gcube.portlets.widgets.wsthreddssync.client.event.ShowMonitorSyncStatusEventHandler; +import org.gcube.portlets.widgets.wsthreddssync.client.rpc.ThreddsWorkspaceSyncServiceAsync; +import org.gcube.portlets.widgets.wsthreddssync.client.view.LoaderIcon; +import org.gcube.portlets.widgets.wsthreddssync.client.view.WsThreddsWidgetViewManager; +import org.gcube.portlets.widgets.wsthreddssync.client.view.binder.MonitorFolderSyncStatusView; +import org.gcube.portlets.widgets.wsthreddssync.shared.WsFolder; +import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderConfiguration; +import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescriptor; + +import com.github.gwtbootstrap.client.ui.Modal; +import com.google.gwt.core.client.GWT; +import com.google.gwt.event.shared.HandlerManager; +import com.google.gwt.user.client.Window; +import com.google.gwt.user.client.rpc.AsyncCallback; + + +// TODO: Auto-generated Javadoc +/** + * The Class WsThreddsWidget. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Feb 14, 2018 + */ +public class WsThreddsWidget { + + /** The ws thredds sync service. */ + public static final ThreddsWorkspaceSyncServiceAsync wsThreddsSyncService = ThreddsWorkspaceSyncServiceAsync.Util.getInstance(); + + /** The Constant eventBus. */ + public final static HandlerManager eventBus = new HandlerManager(null); + + private WsThreddsWidgetViewManager viewManager = new WsThreddsWidgetViewManager(); + + /** + * This is the entry point method. + */ + public WsThreddsWidget() { + bindEvents(); + + } + + /** + * Bind events. + */ + private void bindEvents() { + + eventBus.addHandler(PerformDoSyncEvent.TYPE, new PerformDoSyncEventHandler() { + + @Override + public void onPerformDoSync(PerformDoSyncEvent performDoSyncEvent) { + + if(performDoSyncEvent.getFolder()!=null) + + performFolderSync(performDoSyncEvent.getFolder(), performDoSyncEvent.getConf()); + } + }); + + eventBus.addHandler(ShowMonitorSyncStatusEvent.TYPE, new ShowMonitorSyncStatusEventHandler() { + + @Override + public void onShowMonitorSyncStatus(ShowMonitorSyncStatusEvent showSyncStatusEvent) { + + if(showSyncStatusEvent.getFolder()!=null) + + viewManager.showMonitorSyncToFolder(showSyncStatusEvent.getFolder()); + + } + }); + + } + + + /** + * Show sync folder info. + * + * @param folder the folder + * @throws Exception the exception + */ + public void showSyncFolderInfo(final WsFolder folder) throws Exception { + + if(folder==null || folder.getFolderId()==null) + throw new Exception("Invalid parameter folder null"); + + + MonitorFolderSyncStatusView monitor = viewManager.getMonitor(folder); + + //SHOWING CURRENT ACTIVE MONITOR + if(monitor!=null) { + GWT.log("Monitor for folder: "+folder.getFolderId() +" exists showing it.."); + viewManager.showMonitorSyncToFolder(folder); + return; + } + + + GWT.log("Performing isItemSynched: "+folder.getFolderId()); + final Modal box = new Modal(true); + box.setTitle("Checking configurations..."); + LoaderIcon loader = new LoaderIcon("Checking folder configurations..."); + box.add(loader); + + WsThreddsWidget.wsThreddsSyncService.isItemSynched(folder.getFolderId(), new AsyncCallback() { + + @Override + public void onSuccess(WsThreddsSynchFolderDescriptor result) { + box.hide(); + //GWT.log("WsThreddsSynchFolderDescriptor result: "+result); + viewManager.showThreddsFolderInfo(folder, result); + + } + + @Override + public void onFailure(Throwable caught) { + viewManager.cancelMonitor(folder); + box.hide(); + // TODO Auto-generated method stub + Window.alert(caught.getMessage()); + } + }); + + box.show(); + + } + + + /** + * Perform folder sync. + * + * @param folder the folder + * @param config the config + */ + private void performFolderSync(final WsFolder folder, WsThreddsSynchFolderConfiguration config) { + + GWT.log("Performing doSyncFolder on: "+folder); + final Modal box = new Modal(true); + box.setTitle("Starting synchronization..."); + LoaderIcon loader = new LoaderIcon("Inizializiting synchronization to the folder: "+folder.getFoderName()); + box.add(loader); + + wsThreddsSyncService.doSyncFolder(folder.getFolderId(), config, new AsyncCallback() { + + @Override + public void onFailure(Throwable caught) { + Window.alert(caught.getMessage()); + viewManager.cancelMonitor(folder); + + } + + @Override + public void onSuccess(ThSyncStatus result) { + box.hide(); + GWT.log("Updating sync status: "+result); + viewManager.showMonitorSyncToFolder(folder); + + } + }); + box.show(); + } +} diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/dialog/DialogConfirm.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/dialog/DialogConfirm.java new file mode 100644 index 0000000..3e69775 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/dialog/DialogConfirm.java @@ -0,0 +1,150 @@ +/** + * + */ +package org.gcube.portlets.widgets.wsthreddssync.client.dialog; + + +import org.gcube.portlets.widgets.wsthreddssync.client.resource.Icons; + +import com.google.gwt.dom.client.Style.Unit; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.resources.client.ImageResource; +import com.google.gwt.user.client.ui.Button; +import com.google.gwt.user.client.ui.DialogBox; +import com.google.gwt.user.client.ui.DockPanel; +import com.google.gwt.user.client.ui.HTML; +import com.google.gwt.user.client.ui.HasHorizontalAlignment; +import com.google.gwt.user.client.ui.HorizontalPanel; +import com.google.gwt.user.client.ui.Image; +import com.google.gwt.user.client.ui.VerticalPanel; +import com.google.gwt.user.client.ui.Widget; + + +/** + * The Class DialogConfirm. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Feb 19, 2015 + */ +public class DialogConfirm extends DialogBox implements ClickHandler { + + private DockPanel dock = new DockPanel(); + private Button yesButton; + private VerticalPanel vpContainer; + private ImageResource loading = Icons.ICONS.loading(); + private HorizontalPanel hpButtons = new HorizontalPanel(); + private Button noButton; + /** + * Instantiates a new dialog confirm. + * + * @param img the img + * @param caption the caption + * @param text the text + */ + public DialogConfirm(Image img, String caption, String text) { + getElement().setClassName("gwt-DialogBoxNew"); + dock.setSpacing(4); + dock.setWidth("100%"); + setText(caption); +// setHeading(caption); + + yesButton = new Button("Yes"); + noButton = new Button("No", this); + + noButton.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + hide(); + } + }); + + vpContainer = new VerticalPanel(); + vpContainer.getElement().getStyle().setMargin(20.0, Unit.PX); + vpContainer.add(new HTML(text)); + hpButtons = new HorizontalPanel(); + hpButtons.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); +// hpButtons.getElement().getStyle().setMarginTop(20.0, Unit.PX); + hpButtons.setSpacing(3); + yesButton.getElement().getStyle().setMarginRight(20.0, Unit.PX); + hpButtons.add(yesButton); + hpButtons.add(noButton); + + dock.add(hpButtons, DockPanel.SOUTH); + dock.setCellHorizontalAlignment(hpButtons, DockPanel.ALIGN_CENTER); + + if (img != null) + dock.add(img, DockPanel.WEST); + + dock.add(vpContainer, DockPanel.CENTER); + setWidget(dock); +// add(dock); + } + + /* + * (non-Javadoc) + * + * @see + * com.google.gwt.event.dom.client.ClickHandler#onClick(com.google.gwt.event + * .dom.client.ClickEvent) + */ + @Override + public void onClick(ClickEvent event) { +// hide(); + } + + /** + * Loader. + * + * @param message the message + */ + public void loader(String message){ + try{ + dock.remove(hpButtons); + }catch(Exception e){} + vpContainer.clear(); + HorizontalPanel hpMask = new HorizontalPanel(); + hpMask.add(new Image(loading)); + HTML html = new HTML(message); + html.getElement().getStyle().setMarginLeft(5, Unit.PX); + hpMask.add(html); + vpContainer.add(hpMask); + } + + /** + * Adds the to center panel. + * + * @param w the w + */ + public void addToCenterPanel(Widget w) { + vpContainer.add(w); + } + + /** + * Gets the dock. + * + * @return the dock + */ + public DockPanel getDock() { + return dock; + } + + /** + * Gets the yes button. + * + * @return the yes button + */ + public Button getYesButton() { + return yesButton; + } + + /** + * Gets the no button. + * + * @return the no button + */ + public Button getNoButton() { + return noButton; + } +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/dialog/DialogResult.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/dialog/DialogResult.java new file mode 100644 index 0000000..5be67c9 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/dialog/DialogResult.java @@ -0,0 +1,81 @@ +/** + * + */ +package org.gcube.portlets.widgets.wsthreddssync.client.dialog; + +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.user.client.ui.Button; +import com.google.gwt.user.client.ui.DialogBox; +import com.google.gwt.user.client.ui.DockPanel; +import com.google.gwt.user.client.ui.HTML; +import com.google.gwt.user.client.ui.Image; +import com.google.gwt.user.client.ui.Widget; + +// TODO: Auto-generated Javadoc +/** + * The Class DialogResult. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Jan 19, 2018 + */ +public class DialogResult extends DialogBox implements ClickHandler { + + /** The dock. */ + private DockPanel dock = new DockPanel(); + + /** The close button. */ + private Button closeButton; + + /** + * Instantiates a new dialog result. + * + * @param img the img + * @param title the title + * @param msg the msg + */ + public DialogResult(Image img, String title, String msg) { + getElement().setClassName("gwt-DialogBoxNew"); + setText(title); + closeButton = new Button("Close", this); + dock.setSpacing(4); + dock.setWidth("100%"); + dock.add(new HTML(msg), DockPanel.CENTER); + + dock.add(closeButton, DockPanel.SOUTH); + if(img!=null) + dock.add(img, DockPanel.WEST); + + dock.setCellHorizontalAlignment(closeButton, DockPanel.ALIGN_RIGHT); + setWidget(dock); + } + + + /** + * Gets the close button. + * + * @return the closeButton + */ + public Button getCloseButton() { + return closeButton; + } + + + /* (non-Javadoc) + * @see com.google.gwt.event.dom.client.ClickHandler#onClick(com.google.gwt.event.dom.client.ClickEvent) + */ + @Override + public void onClick(ClickEvent event) { + hide(); + + } + + /** + * Adds the to center panel. + * + * @param w the w + */ + public void addToCenterPanel(Widget w){ + dock.add(w, DockPanel.CENTER); + } +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/event/PerformDoSyncEvent.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/event/PerformDoSyncEvent.java new file mode 100644 index 0000000..88715ac --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/event/PerformDoSyncEvent.java @@ -0,0 +1,67 @@ +package org.gcube.portlets.widgets.wsthreddssync.client.event; + +import org.gcube.portlets.widgets.wsthreddssync.shared.WsFolder; +import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderConfiguration; + +import com.google.gwt.event.shared.GwtEvent; + + +// TODO: Auto-generated Javadoc +/** + * The Class PerformDoSyncEvent. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Feb 15, 2018 + */ +public class PerformDoSyncEvent extends GwtEvent { + + /** The type. */ + public static Type TYPE = new Type(); + private WsThreddsSynchFolderConfiguration conf; + private WsFolder folder; + + + /** + * Instantiates a new perform do sync event. + * + * @param folder the folder + * @param conf the conf + */ + public PerformDoSyncEvent(WsFolder folder, WsThreddsSynchFolderConfiguration conf) { + this.folder = folder; + this.conf = conf; + + } + + /* (non-Javadoc) + * @see com.google.gwt.event.shared.GwtEvent#getAssociatedType() + */ + @Override + public Type getAssociatedType() { + return TYPE; + } + + /* (non-Javadoc) + * @see com.google.gwt.event.shared.GwtEvent#dispatch(com.google.gwt.event.shared.EventHandler) + */ + @Override + protected void dispatch(PerformDoSyncEventHandler handler) { + handler.onPerformDoSync(this); + } + + + /** + * Gets the conf. + * + * @return the conf + */ + public WsThreddsSynchFolderConfiguration getConf() { + return conf; + + } + + public WsFolder getFolder() { + return folder; + } + +} diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/event/PerformDoSyncEventHandler.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/event/PerformDoSyncEventHandler.java new file mode 100644 index 0000000..23fdc2e --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/event/PerformDoSyncEventHandler.java @@ -0,0 +1,22 @@ +package org.gcube.portlets.widgets.wsthreddssync.client.event; + +import com.google.gwt.event.shared.EventHandler; + + +// TODO: Auto-generated Javadoc +/** + * The Interface PerformDoSyncEventHandler. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Feb 15, 2018 + */ +public interface PerformDoSyncEventHandler extends EventHandler { + + + /** + * On change status. + * + * @param courseChangeStatusEvent the course change status event + */ + void onPerformDoSync(PerformDoSyncEvent courseChangeStatusEvent); +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/event/ShowMonitorSyncStatusEvent.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/event/ShowMonitorSyncStatusEvent.java new file mode 100644 index 0000000..8a59c53 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/event/ShowMonitorSyncStatusEvent.java @@ -0,0 +1,54 @@ +package org.gcube.portlets.widgets.wsthreddssync.client.event; + +import org.gcube.portlets.widgets.wsthreddssync.shared.WsFolder; + +import com.google.gwt.event.shared.GwtEvent; + + +// TODO: Auto-generated Javadoc +/** + * The Class PerformDoSyncEvent. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Feb 15, 2018 + */ +public class ShowMonitorSyncStatusEvent extends GwtEvent { + + /** The type. */ + public static Type TYPE = new Type(); + private WsFolder folder; + + + /** + * Instantiates a new perform do sync event. + * + * @param folder the folder + * @param conf the conf + */ + public ShowMonitorSyncStatusEvent(WsFolder folder) { + this.folder = folder; + } + + /* (non-Javadoc) + * @see com.google.gwt.event.shared.GwtEvent#getAssociatedType() + */ + @Override + public Type getAssociatedType() { + return TYPE; + } + + /* (non-Javadoc) + * @see com.google.gwt.event.shared.GwtEvent#dispatch(com.google.gwt.event.shared.EventHandler) + */ + @Override + protected void dispatch(ShowMonitorSyncStatusEventHandler handler) { + handler.onShowMonitorSyncStatus(this); + } + + public WsFolder getFolder() { + return folder; + } + + + +} diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/event/ShowMonitorSyncStatusEventHandler.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/event/ShowMonitorSyncStatusEventHandler.java new file mode 100644 index 0000000..f79d5ce --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/event/ShowMonitorSyncStatusEventHandler.java @@ -0,0 +1,23 @@ +package org.gcube.portlets.widgets.wsthreddssync.client.event; + +import com.google.gwt.event.shared.EventHandler; + + +// TODO: Auto-generated Javadoc +/** + * The Interface ShowMonitorSyncStatusEventHandler. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Feb 16, 2018 + */ +public interface ShowMonitorSyncStatusEventHandler extends EventHandler { + + + + /** + * On show sync status. + * + * @param showSyncStatusEvent the show sync status event + */ + void onShowMonitorSyncStatus(ShowMonitorSyncStatusEvent showSyncStatusEvent); +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/resource/Icons.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/resource/Icons.java new file mode 100644 index 0000000..b568eb2 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/resource/Icons.java @@ -0,0 +1,31 @@ +/** + * + */ +package org.gcube.portlets.widgets.wsthreddssync.client.resource; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.resources.client.ClientBundle; +import com.google.gwt.resources.client.ImageResource; + + +// TODO: Auto-generated Javadoc +/** + * The Interface Icons. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Feb 7, 2018 + */ +public interface Icons extends ClientBundle { + + /** The Constant ICONS. */ + public static final Icons ICONS = GWT.create(Icons.class); + + /** + * Loading. + * + * @return the image resource + */ + @Source("loading.gif") + ImageResource loading(); + +} diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/resource/loading.gif b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/resource/loading.gif new file mode 100644 index 0000000000000000000000000000000000000000..27f0eeec008138a3340f8c6bf8badcd2f5503054 GIT binary patch literal 2533 zcmZwJYfw|^83*t;CnuboBqn%rAq5gb2#|zZz<}W*5(p##L_r0STf#LUmqdt$fEq%$ z1eA*+qJoN|BCZr2Z>!QG=<2Gq*xl*4JL4|Utwp=t(fXzBwAur9+uaV|&zbZ5=6~Mz z`Kz@_ib%aXa0l;*0HpK*0KQ#(D<~X(|NaAQ^HFm8kxk9l;w;o6gu5cbv0ZNNN95kvL>#>N|2&YHU^+y7~lM5@_x3~ zczH4}WAJL-oW;P;EDX+9FW0*Wjn!rrsmWm!|nK203t#ODSEV;X(yq16vUl z6B`#V43Pk;SQ4HKAxZw2B%t4;3G*s#$zA=Q@d-a2|B`HZ{L#%*Tb9PxSr67b3g`O% z6qb7aS^J|x4w|sZ*`+m^76Cca#dIqjo|xIFvJB83P2F`2Tqmba>4mfGD?v>?XJx+I z`|r8Z-Hfl^WDve}AIJb}8o4}belsfv(Aqgwpr&~zP!UQ%S!0D?az|dBPP$RXXyd?# zwz28{S}vpqY3#`8-eRTy;Y693K%4{-W+Y1PUuY1z%SmLxfdeZF?tB!8w*W5Oinh%U zIq!Me#gQ*Rr4fC6Z8&0qjV2l5xq~dXHipfR2e*IGC2Z%la;ImCjLCF9oT+Mu=&Yo| zIWr07#YM|@Ax0p2@t&6AqHJXQkuW~d&PoEUUQT8w#-o~dRkRaIBf7B!3SZ(hL$Rb< zA!IvVpg+th;TxD+`HXRuB@Y*E@F@kG+3VWQpr(4E3=Grcp}EsO$Z?B*+4Id zgTX6;?*14F5F<@_(|U`zM`M>IKXnGr=wum%@-tT~EpUR$n-&w$`3EHKW-ttQs8>IX z55Yl}D;NBYzwLB6EVgeSFk8hbl#Qm~u=R`3NY|N=@=HY`+?K>E=B0g~s zi^#VDdo$Jo>On)tUN5ZHybH1rDgfF+ssgX# zW7MIw{SaCPOm6hbn$R^8mrYgheu?gm8|+ag5cc-2h`I9r7=zVyY5J?^hNxG*K@#>M|09r4FZ4A%X{f+fa8*+lU> zUs@>YOlx-3&PkyMjB@UE=>d;F&ZWot(tkUD<8PihcDn8C8_{^5L+!1!a2HP^-md~1 zO`l&7yrumWN9+OnYy>+ngWYWnRW&xK7Q@eeeFdlt&Lb753Kd&GW>z-HS--)SUXXYS z)248vNHMIq_>CcwFu5c{hvZ45m)+bw`2t~E+luqw_*o1b6E}a1?-LpRDvV~RkQaN% z(S%gH>cPxS1xIlN5Hy+awbPw~RsZxu7z?khJX>e?`0aOBStsD52j7TA*>UEe+2knd z4^g(I7#i?jYAFWH0d|9WXQP)<3-5^9S4X`GABnX5(Ju6zS{Va>;^FxcF2k%Pj9?Q6+ z&w3tBge_&!r8b!Y0n!iVC7)@XgR1*sw=D9?Em(ijv7?$&ouyoU+4~ZRd*e zzUIALzk)Fdos$A@W*do$OA4N7T)9U<|arp8)BULrgKy zu&TSEBm+v+*A)kB-pa6_AIW9YCFIJYO}q?t43Bi21NWZOZso}%2GPhm2uYFF`d*+Q zNu;dP^DByOFN+3ffRX`~qKJ=gF2!@0t8nSjJdxeIfUlV8RgMlpx<(RA_X5w{y)&Xa zz;1E}nb9@;3x&}&({29KW8_BCc#2FjAfh~dvK39aV_W;8Fev!@1_BKwV(XjO9{7da z($4I_s;u3iB+S+h6_~pTVxX2gDuhrX*kI8$6nP>U3dT_ud@2VArE;NSkj`G`Nvbw? z3=3saYDA4Vs!o(Fsig%TqadSkC%#!Zp&yq%ihJ;-KSdB5mzMsbd} literal 0 HcmV?d00001 diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/rpc/ThreddsWorkspaceSyncService.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/rpc/ThreddsWorkspaceSyncService.java new file mode 100644 index 0000000..3f87688 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/rpc/ThreddsWorkspaceSyncService.java @@ -0,0 +1,27 @@ +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.ThSyncStatus; +import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeVRE; +import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderConfiguration; +import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescriptor; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +/** + * The client side stub for the RPC service. + */ +@RemoteServiceRelativePath("wsthreddssync") +public interface ThreddsWorkspaceSyncService extends RemoteService { + + WsThreddsSynchFolderDescriptor isItemSynched(String folderId) throws ItemNotSynched, Exception; + + ThSyncStatus doSyncFolder(final String folderId, WsThreddsSynchFolderConfiguration clientConfig) throws Exception; + + ThSyncStatus monitorSyncStatus(String folderId) throws ItemNotSynched, Exception; + + List getListOfVREsForLoggedUser() throws Exception; +} diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/rpc/ThreddsWorkspaceSyncServiceAsync.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/rpc/ThreddsWorkspaceSyncServiceAsync.java new file mode 100644 index 0000000..89ed5de --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/rpc/ThreddsWorkspaceSyncServiceAsync.java @@ -0,0 +1,49 @@ +package org.gcube.portlets.widgets.wsthreddssync.client.rpc; + +import java.util.List; + +import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus; +import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeVRE; +import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderConfiguration; +import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescriptor; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.rpc.AsyncCallback; + +public interface ThreddsWorkspaceSyncServiceAsync +{ + + /** + * Utility class to get the RPC Async interface from client-side code + */ + public static final class Util + { + private static ThreddsWorkspaceSyncServiceAsync instance; + + public static final ThreddsWorkspaceSyncServiceAsync getInstance() + { + if ( instance == null ) + { + instance = (ThreddsWorkspaceSyncServiceAsync) GWT.create( ThreddsWorkspaceSyncService.class ); + } + return instance; + } + + private Util() + { + // Utility class should not be instantiated + } + } + + + void isItemSynched(String folderId, AsyncCallback callback); + + + void doSyncFolder(String folderId, WsThreddsSynchFolderConfiguration clientConfig, AsyncCallback callback); + + + void monitorSyncStatus(String folderId, AsyncCallback callback); + + + void getListOfVREsForLoggedUser(AsyncCallback> callback); +} diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/FormatUtil.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/FormatUtil.java new file mode 100644 index 0000000..2e7df80 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/FormatUtil.java @@ -0,0 +1,40 @@ +package org.gcube.portlets.widgets.wsthreddssync.client.view; + +// TODO: Auto-generated Javadoc +/** + * The Class FormatUtil. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Feb 16, 2018 + */ +public class FormatUtil { + + + /** + * Truncate a string and add an ellipsis ('...') to the end if it exceeds the + * specified length. + * + * @param value the string to truncate + * @param len the maximum length to allow before truncating + * @return the converted text + */ + public static String ellipse(String value, int len) { + if (value != null && value.length() > len) { + return value.substring(0, len - 3) + "..."; + } + return value; + } + + + /** + * Gets the folder title. + * + * @param folderName the folder name + * @param maxSize the max size + * @return the folder title + */ + public static String getFolderTitle(String folderName, int maxSize){ + String title = folderName!=null&&folderName.length()>0?folderName:""; + return FormatUtil.ellipse(title, maxSize); + } +} diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/LoaderIcon.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/LoaderIcon.java new file mode 100644 index 0000000..3efdd2b --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/LoaderIcon.java @@ -0,0 +1,61 @@ +/** + * + */ +package org.gcube.portlets.widgets.wsthreddssync.client.view; + +import org.gcube.portlets.widgets.wsthreddssync.client.resource.Icons; + +import com.google.gwt.user.client.ui.HTML; +import com.google.gwt.user.client.ui.HorizontalPanel; +import com.google.gwt.user.client.ui.Image; + +/** + * The Class LoaderIcon. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Feb 19, 2015 + */ +public class LoaderIcon extends HorizontalPanel{ + + + private Image imgLoading = new Image(Icons.ICONS.loading()); + private HTML txtLoading = new HTML(""); + + /** + * Instantiates a new loader icon. + * + * @param txtHTML the txt html + */ + public LoaderIcon(String txtHTML) { + this(); + setText(txtHTML); + } + + /** + * Instantiates a new loader icon. + */ + public LoaderIcon() { + setStyleName("marginTop20"); + add(imgLoading); + add(txtLoading); + } + + /** + * Sets the text. + * + * @param txtHTML the new text + */ + public void setText(String txtHTML){ + txtLoading.setHTML(""+txtHTML+""); + } + + /** + * Show. + * + * @param bool the bool + */ + public void show(boolean bool){ + this.setVisible(bool); + } + +} diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/WsThreddsWidgetViewManager.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/WsThreddsWidgetViewManager.java new file mode 100644 index 0000000..27e7751 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/WsThreddsWidgetViewManager.java @@ -0,0 +1,359 @@ +package org.gcube.portlets.widgets.wsthreddssync.client.view; + + + +import java.util.HashMap; +import java.util.Map; + +import org.gcube.portal.wssynclibrary.shared.thredds.Status; +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; +import org.gcube.portlets.widgets.wsthreddssync.client.event.ShowMonitorSyncStatusEvent; +import org.gcube.portlets.widgets.wsthreddssync.client.view.binder.AbstractViewDialogBox; +import org.gcube.portlets.widgets.wsthreddssync.client.view.binder.CreateThreddsConfigurationView; +import org.gcube.portlets.widgets.wsthreddssync.client.view.binder.MonitorFolderSyncStatusView; +import org.gcube.portlets.widgets.wsthreddssync.client.view.binder.ShowThreddsFolderInfoView; +import org.gcube.portlets.widgets.wsthreddssync.shared.WsFolder; +import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderConfiguration; +import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescriptor; + +import com.github.gwtbootstrap.client.ui.Alert; +import com.github.gwtbootstrap.client.ui.Modal; +import com.github.gwtbootstrap.client.ui.constants.AlertType; +import com.google.gwt.core.shared.GWT; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.user.client.Timer; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.gwt.user.client.ui.Button; +import com.google.gwt.user.client.ui.VerticalPanel; + + +// TODO: Auto-generated Javadoc +/** + * The Class WsThreddsWidgetViewManager. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Feb 19, 2018 + */ +public class WsThreddsWidgetViewManager { + + private Map mapMonitor = new HashMap(); + + + /** + * Instantiates a new ws thredds widget view manager. + */ + public WsThreddsWidgetViewManager() { + } + + + /** + * Cancel monitor. + * + * @param folder the folder + */ + public void cancelMonitor(WsFolder folder) { + try { + MonitorFolderSyncStatusView monitorView = getMonitor(folder); + if(monitorView.getSchedulerTime()!=null) { + GWT.log("Removed sheduler time on folder: "+folder.getFolderId()); + monitorView.getSchedulerTime().cancel(); + } + GWT.log("Removed monitor on folder: "+folder.getFolderId()); + mapMonitor.remove(folder.getFolderId()); + }catch (Exception e) { + GWT.log("Error on removing map monitor for id: "+folder.getFolderId());; + } + } + + + /** + * Gets the monitor. + * + * @param folder the folder + * @return the monitor + */ + public MonitorFolderSyncStatusView getMonitor(WsFolder folder){ + + if(folder==null) + return null; + + return mapMonitor.get(folder.getFolderId()); + } + + + /** + * Save monitor. + * + * @param folder the folder + * @param monitor the monitor + */ + private void saveMonitor(WsFolder folder, MonitorFolderSyncStatusView monitor) { + mapMonitor.put(folder.getFolderId(), monitor); + } + + + /** + * Show monitor sync to folder. + * + * @param folder the folder + */ + public void showMonitorSyncToFolder(final WsFolder folder) { + + final Modal box = new Modal(true); + box.addStyleName("ws-thredds-modal-body"); + box.setTitle("Monitor transferring of: "+FormatUtil.getFolderTitle(folder.getFoderName(), 20)); + box.setWidth(800); + //box.setHeight("600px"); + //box.setHeight("700px"); + //box.getElement().getStyle().setZIndex(10000); + MonitorFolderSyncStatusView monitorView = getMonitor(folder); + + final MonitorFolderSyncStatusView theMonitor = monitorView; + + final AbstractViewDialogBox panelView = new AbstractViewDialogBox() { + + @Override + public void closeHandler() { + box.hide(); + if(theMonitor!=null && theMonitor.getSchedulerTime()!=null) + theMonitor.getSchedulerTime().cancel(); + + } + }; + + if(monitorView==null) { + + monitorView = new MonitorFolderSyncStatusView() { + + @Override + public void submitHandler() { + //TODO CLIENT SIDE? + cancelMonitor(folder); + box.hide(); + } + + @Override + public void setError(boolean visible, String error) { + panelView.setError(visible, error); + } + }; + } + + //Removing old monitor + cancelMonitor(folder); + //Creating new one + final MonitorFolderSyncStatusView currentMonitor = monitorView; + + + Timer schedulingTimer = new Timer() { + + @Override + public void run() { + + WsThreddsWidget.wsThreddsSyncService.monitorSyncStatus(folder.getFolderId(), new AsyncCallback() { + + @Override + public void onFailure(Throwable caught) { + cancelMonitor(folder); + + } + + @Override + public void onSuccess(ThSyncStatus status) { + + currentMonitor.updateStatusView(folder, status); + + if(status!=null && status.getProcessStatus()!=null) { + + if(status.getProcessStatus().getStatus().equals(Status.COMPLETED)) { + GWT.log("Sync completed cancel the polling: "+status); + cancelMonitor(folder); + } + } + } + }); + } + }; + + schedulingTimer.scheduleRepeating(2000); + currentMonitor.setScheduler(schedulingTimer); + saveMonitor(folder, currentMonitor); + + panelView.addViewAsWidget(monitorView); + box.add(panelView); + box.show(); + + } + + + /** + * Show create configuration folder. + * + * @param folder the folder + * @param conf the conf + */ + public void showCreateConfigurationFolder(final WsFolder folder, WsThreddsSynchFolderDescriptor conf){ + + final Modal box = new Modal(true); + box.setTitle("Create Thredds Sync Configuration for: "+FormatUtil.getFolderTitle(folder.getFoderName(), 20)); + //box.getElement().getStyle().setZIndex(10000); + + final AbstractViewDialogBox panelView = new AbstractViewDialogBox() { + + @Override + public void closeHandler() { + box.hide(); + + } + }; + + CreateThreddsConfigurationView createThreddsConfiguration = new CreateThreddsConfigurationView(folder.getFolderId()) { + + @Override + public void submitHandler() { + box.hide(); + WsThreddsSynchFolderConfiguration conf = new WsThreddsSynchFolderConfiguration(); + conf.setFilter(null); + conf.setRemotePath(getRemotePath()); + conf.setCatalogName(getCatalogueName()); + conf.setTheVRE(getSelectedVRE()); + WsThreddsWidget.eventBus.fireEvent(new PerformDoSyncEvent(folder, conf)); + } + + @Override + public void setError(boolean visible, String error) { + panelView.setError(visible, error); + + } + }; + + panelView.addViewAsWidget(createThreddsConfiguration); + box.add(panelView); + box.show(); + + } + + + /** + * Show thredds folder info. + * + * @param folder the folder + * @param folderDescriptor the folder descriptor + */ + public void showThreddsFolderInfo(final WsFolder folder, final WsThreddsSynchFolderDescriptor folderDescriptor){ + GWT.log("ShowThreddsFolderInfo folder: "+folder); + GWT.log("WsThreddsSynchFolderDescriptor is: "+folderDescriptor); + + final Modal box = new Modal(true); + //box.setWidth(WIDHT_DIALOG+"px"); + box.setTitle("Thredds Sync Information for: "+FormatUtil.getFolderTitle(folder.getFoderName(), 20)); + //box.getElement().getStyle().setZIndex(10000); + + final AbstractViewDialogBox panelView = new AbstractViewDialogBox() { + + @Override + public void closeHandler() { + box.hide(); + + } + }; + + boolean isCreateConfiguration = folderDescriptor==null?true:false; + + + ShowThreddsFolderInfoView folderInfo = new ShowThreddsFolderInfoView(folder.getFolderId(), isCreateConfiguration) { + + @Override + public void submitHandler(SUBMIT_ACTION action) { + + if(action==null) + return; + + switch (action) { + + case CREATE_UPDATE_CONFIGURATION: + if(folderDescriptor==null) { + GWT.log("Performing a create configuration"); + //PERFORM A CREATE CONFIGURATION (AT FIRST TIME), THE CONFIGURATION DOES NOT EXITS + showCreateConfigurationFolder(folder, null); + + } +// else { +// GWT.log("Performing an updated configuration"); +// //PERFORM AN UPDATE CONFIGURATION. THE CONFIGURATION EXIST +// //BeanConverter.toWsThreddsFolderConfig(t, vre); +// showCreateConfigurationFolder(folder, result); +// } +// + + break; + case DO_SYNC: + GWT.log("Performing a do sync using server folder configuration"); + //PERFORM A DO SYNC BUT NOT AT FIRST TIME + WsThreddsWidget.eventBus.fireEvent(new PerformDoSyncEvent(folder, null)); + + break; + + default: + break; + } + + } + @Override + public void setError(boolean visible, String error) { + panelView.setError(visible, error); + } + }; + + folderInfo.updateViewToResult(folder, folderDescriptor); + + if(isCreateConfiguration) { + folderInfo.getMainPanel().setVisible(false); + folderInfo.setError(true, "This Folder is not sychronized. Do you want create a configuration?"); + folderInfo.getPager().getLeft().setText("Create Configuration"); +// folderInfo.getPager().getLeft().setText("Create Configuration"); +// folderInfo.getPager().getLeft().addClickHandler(new ClickHandler() { +// +// @Override +// public void onClick(ClickEvent event) { +// } +// }); + }else { + //USER CAN PERFORM DO SYNC + //MOREOVER, HE/SHE COULD UPDATE THE CONFIGURATION BUT IT IS NOT SUPPORTED SERVER-SIDE + folderInfo.getPager().getLeft().setVisible(false); + + if(folderDescriptor.getServerFolderDescriptor().isLocked()) { + VerticalPanel v = new VerticalPanel(); + Alert alert = new Alert("Current Folder synchronization is locked by another proccess. Do you want see synchronization status?"); + alert.setClose(true); + alert.setType(AlertType.INFO); + + Button butt = new Button("Show Status"); + butt.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + WsThreddsWidget.eventBus.fireEvent(new ShowMonitorSyncStatusEvent(folder)); + } + }); + + v.add(alert); + v.add(butt); + box.add(v); + } + + } + + panelView.addViewAsWidget(folderInfo); + box.add(panelView); + box.show(); + + } + + + +} diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/AbstractViewDialogBox.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/AbstractViewDialogBox.java new file mode 100644 index 0000000..dd8b429 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/AbstractViewDialogBox.java @@ -0,0 +1,157 @@ +package org.gcube.portlets.widgets.wsthreddssync.client.view.binder; + + +import org.gcube.portlets.widgets.wsthreddssync.client.view.LoaderIcon; + +import com.github.gwtbootstrap.client.ui.Alert; +import com.github.gwtbootstrap.client.ui.Button; +import com.github.gwtbootstrap.client.ui.FluidRow; +import com.github.gwtbootstrap.client.ui.base.AlertBase; +import com.github.gwtbootstrap.client.ui.constants.AlertType; +import com.google.gwt.core.client.GWT; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.uibinder.client.UiBinder; +import com.google.gwt.uibinder.client.UiField; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.HTMLPanel; +import com.google.gwt.user.client.ui.ScrollPanel; +import com.google.gwt.user.client.ui.Widget; + + +// TODO: Auto-generated Javadoc +/** + * The Class AbstractViewDialogBox. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Jan 8, 2018 + */ +public abstract class AbstractViewDialogBox extends Composite { + + /** The ui binder. */ + private static AbstractViewDialogBoxUiBinder uiBinder = + GWT.create(AbstractViewDialogBoxUiBinder.class); + + /** The default width. */ + public static int DEFAULT_WIDTH = 500; + + /** + * The Interface AbstractViewDialogBoxUiBinder. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Jan 9, 2018 + */ + interface AbstractViewDialogBoxUiBinder + extends UiBinder { + } + + + /** The button close dialog. */ + @UiField + Button button_close_dialog; + + /** The field root panel. */ + @UiField + HTMLPanel field_root_panel; + + /** The scroll panel. */ + @UiField + ScrollPanel scroll_panel; + + /** The validator field. */ + @UiField + FluidRow validator_field; + + /** The loader icon. */ + private LoaderIcon loaderIcon = new LoaderIcon(); + + /** The alert error. */ + protected Alert alertError = new Alert(); + + + /** The alert info. */ + protected AlertBase alertInfo = new Alert(); + + /** + * Close handler. + */ + public abstract void closeHandler(); + + /** + * Because this class has a default constructor, it can + * be used as a binder template. In other words, it can be used in other + * *.ui.xml files as follows: + * + * Hello! + * + * Note that depending on the widget that is used, it may be necessary to + * implement HasHTML instead of HasText. + */ + public AbstractViewDialogBox() { + + initWidget(uiBinder.createAndBindUi(this)); + //setWidth(DEFAULT_WIDTH+"px"); + + alertError.setType(AlertType.ERROR); + alertError.setVisible(false); + alertError.setClose(false); + validator_field.add(alertError); + + showLoading(false, ""); + field_root_panel.add(loaderIcon); + + bindEvents(); + } + + /** + * Bind events. + */ + private void bindEvents() { + + button_close_dialog.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + closeHandler(); + + } + }); + } + + + /** + * Adds the view as widget. + * + * @param child the child + */ + public void addViewAsWidget(Widget child) { + + scroll_panel.add(child); + } + + /** + * Show loading. + * + * @param visible the visible + * @param text the text + */ + public void showLoading(boolean visible, String text){ + loaderIcon.setVisible(visible); + loaderIcon.setText(text); + } + + + /** + * Sets the error. + * + * @param visible the visible + * @param error the error + */ + public void setError(boolean visible, String error) { + alertError.setVisible(visible); + alertError.setText(error==null?"":error); + } + + +} diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/AbstractViewDialogBox.ui.xml b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/AbstractViewDialogBox.ui.xml new file mode 100644 index 0000000..cc6a5e6 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/AbstractViewDialogBox.ui.xml @@ -0,0 +1,14 @@ + + + + + + + + + + Close + + + \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/CreateThreddsConfigurationView.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/CreateThreddsConfigurationView.java new file mode 100644 index 0000000..054d947 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/CreateThreddsConfigurationView.java @@ -0,0 +1,216 @@ +package org.gcube.portlets.widgets.wsthreddssync.client.view.binder; + + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.gcube.portlets.widgets.wsthreddssync.client.WsThreddsWidget; +import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeVRE; + +import com.github.gwtbootstrap.client.ui.ControlGroup; +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.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.uibinder.client.UiBinder; +import com.google.gwt.uibinder.client.UiField; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.Widget; + + +// TODO: Auto-generated Javadoc +/** + * The Class CreateThreddsConfigurationView. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Feb 15, 2018 + */ +public abstract class CreateThreddsConfigurationView extends Composite { + + /** The ui binder. */ + private static CreateThreddsConfigurationViewUiBinder uiBinder = + GWT.create(CreateThreddsConfigurationViewUiBinder.class); + + + /** + * The Interface CreateFolderConfigurationToThreddsSyncUiBinder. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Feb 14, 2018 + */ + interface CreateThreddsConfigurationViewUiBinder + extends UiBinder { + } + + /** The pager. */ + @UiField + Pager pager; + + + /** The field course desciption. */ + @UiField + ListBox field_select_vre; + + + /** The field catalogue name. */ + @UiField + TextBox field_catalogue_name; + + /** The field folder name. */ + @UiField + TextBox field_remote_path; + + + /** The cg catalogue name. */ + @UiField + ControlGroup cg_catalogue_name; + + /** The cg folder name. */ + @UiField + ControlGroup cg_remote_path; + + + /** The folder id. */ + private String folderId; + + /** The map VR es. */ + private Map mapVREs = new HashMap(); + + + /** + * Submit handler. + */ + public abstract void submitHandler(); + + /** + * Sets the error. + * + * @param visible the visible + * @param error the error + */ + public abstract void setError(boolean visible, String error); + + + /** + * Because this class has a default constructor, it can + * be used as a binder template. In other words, it can be used in other + * *.ui.xml files as follows: + * + * Hello! + * + * Note that depending on the widget that is used, it may be necessary to + * implement HasHTML instead of HasText. + * + * @param folderId the folder id + */ + public CreateThreddsConfigurationView(String folderId) { + 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(); + + } + }); + + WsThreddsWidget.wsThreddsSyncService.getListOfVREsForLoggedUser(new AsyncCallback>() { + + @Override + public void onSuccess(List 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 + + } + }); + + } + + + /** + * Validate submit. + * + * @return true, if successful + */ + 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_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 '/'"); + return false; + } + + return true; + } + + + /** + * Gets the remote path. + * + * @return the remote path + */ + public String getRemotePath() { + return field_remote_path.getValue(); + } + + /** + * Gets the catalogue name. + * + * @return the catalogue name + */ + public String getCatalogueName(){ + return field_catalogue_name.getValue(); + } + + + /** + * Gets the unit description. + * + * @return the unit description + */ + public GcubeVRE getSelectedVRE(){ + String item = field_select_vre.getSelectedItemText(); + String text = field_select_vre.getSelectedValue(); + return mapVREs.get(item); + } + + + + +} diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/CreateThreddsConfigurationView.ui.xml b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/CreateThreddsConfigurationView.ui.xml new file mode 100644 index 0000000..8f9d1cd --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/CreateThreddsConfigurationView.ui.xml @@ -0,0 +1,44 @@ + + + + .noBorder { + border: 0px; + } + + + + + + + Catalogue Name + + + + + + + Publish in the VRE + + + + + + + + Remote Path + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/MonitorFolderSyncStatusView.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/MonitorFolderSyncStatusView.java new file mode 100644 index 0000000..bcc932d --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/MonitorFolderSyncStatusView.java @@ -0,0 +1,274 @@ +package org.gcube.portlets.widgets.wsthreddssync.client.view.binder; + + +import org.gcube.portal.wssynclibrary.shared.thredds.Status; +import org.gcube.portal.wssynclibrary.shared.thredds.ThProcessStatus; +import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus; +import org.gcube.portlets.widgets.wsthreddssync.client.view.LoaderIcon; +import org.gcube.portlets.widgets.wsthreddssync.shared.WsFolder; + +import com.github.gwtbootstrap.client.ui.Alert; +import com.github.gwtbootstrap.client.ui.Pager; +import com.github.gwtbootstrap.client.ui.ProgressBar; +import com.github.gwtbootstrap.client.ui.TextArea; +import com.github.gwtbootstrap.client.ui.TextBox; +import com.github.gwtbootstrap.client.ui.constants.AlertType; +import com.github.gwtbootstrap.client.ui.constants.ResizeType; +import com.google.gwt.core.client.GWT; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.uibinder.client.UiBinder; +import com.google.gwt.uibinder.client.UiField; +import com.google.gwt.user.client.Timer; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.HTMLPanel; +import com.google.gwt.user.client.ui.Widget; + + + +// TODO: Auto-generated Javadoc +/** + * The Class ShowThreddsFolderInfoView. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Feb 15, 2018 + */ +public abstract class MonitorFolderSyncStatusView extends Composite { + + //private static final String DATE_FORMAT_YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss"; + + + public static final String TRANSFERRING_STATE = "Transferring state: "; + + private static final String UNKNOWN = "UNKNOWN"; + + /** The ui binder. */ + private static MonitorFolderSyncStatusViewUiBinder uiBinder = + GWT.create(MonitorFolderSyncStatusViewUiBinder.class); + + /** + * The Interface ShowThreddsFolderInfoViewUiBinder. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Feb 15, 2018 + */ + interface MonitorFolderSyncStatusViewUiBinder + extends UiBinder { + } + + + @UiField + Pager pager; + + @UiField + ProgressBar progress_percentage; + + + @UiField + TextArea field_current_message; + + @UiField + TextBox field_queued_items; + + + @UiField + TextBox field_transferred_items; + + + @UiField + TextBox field_number_error; + + @UiField + TextArea field_history_messages; + + @UiField + HTMLPanel form_monitor_thredds_transfer; + + @UiField + HTMLPanel field_loader; + + private WsFolder folder; + + + /** The scheduler time. */ + private Timer schedulerTime; + + + /** + * Submit handler. + */ + public abstract void submitHandler(); + + /** + * Sets the error. + * + * @param visible the visible + * @param error the error + */ + public abstract void setError(boolean visible, String error); + + + /** + * Because this class has a default constructor, it can + * be used as a binder template. In other words, it can be used in other + * *.ui.xml files as follows: + * + * Hello! + * + * Note that depending on the widget that is used, it may be necessary to + * implement HasHTML instead of HasText. + */ + public MonitorFolderSyncStatusView() { + + initWidget(uiBinder.createAndBindUi(this)); + + pager.getLeft().setVisible(false); + + pager.getRight().addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + setError(false, ""); + submitHandler(); + + } + }); + + field_history_messages.setHeight("200px"); + field_history_messages.setResize(ResizeType.BOTH); + field_current_message.setHeight("80px"); + field_current_message.setResize(ResizeType.BOTH); + } + + + /** + * Update status view. + * + * @param folder the folder + * @param syncStatus the sync status + */ + public void updateStatusView(WsFolder folder, ThSyncStatus syncStatus) { + + field_loader.clear(); + LoaderIcon loader = new LoaderIcon("Waiting..."); + field_loader.add(loader); + + this.folder = folder; + this.field_current_message.setValue(UNKNOWN); + setFieldValue(this.field_number_error, UNKNOWN); + setFieldValue(this.field_queued_items, UNKNOWN); + setFieldValue(this.field_transferred_items, UNKNOWN); + this.field_history_messages.setValue(UNKNOWN); + + if(folder==null || syncStatus==null || syncStatus.getProcessStatus()==null) { + //setError(true, "Sync status error: either folder does not exist or the status is null"); + GWT.log("Sync status error: either folder does not exist or the status is null"); + return; + } + + ThProcessStatus process = syncStatus.getProcessStatus(); + + if(process.getPercentCompleted()>=0) + progress_percentage.setPercent((int)process.getPercentCompleted()*100); + + if(process.getStatus()!=null) + + if(syncStatus.getProcessStatus().getStatus()!=null) { + loader.setText(syncStatus.getProcessStatus().getStatus().toString()); + + switch (syncStatus.getProcessStatus().getStatus()) { + case INITIALIZING: + field_loader.clear(); + field_loader.add(new LoaderIcon(TRANSFERRING_STATE+Status.INITIALIZING.toString())); + break; + + case ONGOING: + field_loader.clear(); + field_loader.add(new LoaderIcon(TRANSFERRING_STATE+Status.ONGOING.toString())); + break; + case WARNINGS: + field_loader.clear(); + field_loader.add(new LoaderIcon(TRANSFERRING_STATE+Status.WARNINGS.toString())); + break; + case COMPLETED: + field_loader.clear(); + Alert alert = new Alert("Transferring " +Status.COMPLETED.toString()); + alert.setClose(false); + alert.setType(AlertType.SUCCESS); + field_loader.add(alert); + break; + + case STOPPED: + field_loader.clear(); + Alert alert1 = new Alert("Transferring " +Status.STOPPED.toString()); + alert1.setClose(false); + alert1.setType(AlertType.WARNING); + field_loader.add(alert1); + //progress_percentage.setVisible(false); + break; + + default: + break; + } + } + + if(process.getCurrentMessage()!=null) + this.field_current_message.setValue(process.getCurrentMessage()); + + if(process.getErrorCount()!=null) + this.field_number_error.setValue(process.getErrorCount().toString()); + + + if(process.getQueuedTransfers()!=null) + this.field_queued_items.setValue(process.getQueuedTransfers().toString()); + + if(process.getServedTransfers()!=null) + this.field_transferred_items.setValue(process.getServedTransfers().toString()); + + if(process.getLogBuilder()!=null) + this.field_history_messages.setValue(process.getLogBuilder().toString()); + + } + + + /** + * Sets the field value. + * + * @param box the box + * @param value the value + */ + private void setFieldValue(TextBox box, String value) { + box.setValue(value); + } + + + /** + * Validate submit. + * + * @return true, if successful + */ + protected boolean validateSubmit() { + + return true; + } + + + /** + * Sets the scheduler. + * + * @param schedulingTimer the new scheduler + */ + public void setScheduler(Timer schedulingTimer) { + this.schedulerTime = schedulingTimer; + } + + /** + * Gets the scheduling time. + * + * @return the scheduling time + */ + public Timer getSchedulerTime() { + return schedulerTime; + } +} diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/MonitorFolderSyncStatusView.ui.xml b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/MonitorFolderSyncStatusView.ui.xml new file mode 100644 index 0000000..2e663ea --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/MonitorFolderSyncStatusView.ui.xml @@ -0,0 +1,98 @@ + + + + .noBorder { + border: 0px; + } + + .myWidth { + width: 500px; + } + + .myPaddingLeft{ + padding-left: 180px; + } + .myLittleWidth { + width: 20px; + } + + .myFormWidth { + width: 750px; + } + + + + + + + + + + Items in queue + + + + + + + + Transferred items + + + + + + + + + Number of Errors + + + + + + + + + + + + + + + + + Status Message + + + + + + + Transfer History + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/ShowThreddsFolderInfoView.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/ShowThreddsFolderInfoView.java new file mode 100644 index 0000000..cfb16eb --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/ShowThreddsFolderInfoView.java @@ -0,0 +1,320 @@ +package org.gcube.portlets.widgets.wsthreddssync.client.view.binder; + + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.gcube.portal.wssynclibrary.shared.thredds.ThProcessDescriptor; +import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor; +import org.gcube.portal.wssynclibrary.shared.thredds.ThSynchFolderConfiguration; +import org.gcube.portlets.widgets.wsthreddssync.client.WsThreddsWidget; +import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeVRE; +import org.gcube.portlets.widgets.wsthreddssync.shared.WsFolder; +import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescriptor; + +import com.github.gwtbootstrap.client.ui.ControlGroup; +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.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.uibinder.client.UiBinder; +import com.google.gwt.uibinder.client.UiField; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.HTMLPanel; +import com.google.gwt.user.client.ui.Widget; + + + +// TODO: Auto-generated Javadoc +/** + * The Class ShowThreddsFolderInfoView. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Feb 15, 2018 + */ +public abstract class ShowThreddsFolderInfoView extends Composite { + + private static final String DATE_FORMAT_YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss"; + + + /** The ui binder. */ + private static ShowThreddsFolderInfoViewUiBinder uiBinder = + GWT.create(ShowThreddsFolderInfoViewUiBinder.class); + + /** + * The Interface ShowThreddsFolderInfoViewUiBinder. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Feb 15, 2018 + */ + interface ShowThreddsFolderInfoViewUiBinder + extends UiBinder { + } + + + @UiField + TextBox field_folder_status; + + @UiField + ListBox field_select_vre; + + + @UiField + TextBox field_catalogue_name; + + + @UiField + TextBox field_remote_path; + + @UiField + TextBox field_folder_path; + + + @UiField + TextBox field_folder_locked; + + + /*@UiField + TextBox field_last_sync; + */ + + + @UiField + ControlGroup cg_catalogue_name; + + + @UiField + ControlGroup cg_remote_path; + + @UiField + HTMLPanel form_unit_fields; + + @UiField + Pager pager; + + + + /** The folder id. */ + private String folderId; + + /** The map VR es. */ + private Map mapVREs = new HashMap(); + + + private boolean isCreateConfiguration; + + + public static enum SUBMIT_ACTION {CREATE_UPDATE_CONFIGURATION, DO_SYNC}; + + /** + * Submit handler. + */ + public abstract void submitHandler(SUBMIT_ACTION action); + + /** + * Sets the error. + * + * @param visible the visible + * @param error the error + */ + public abstract void setError(boolean visible, String error); + + + /** + * Because this class has a default constructor, it can + * be used as a binder template. In other words, it can be used in other + * *.ui.xml files as follows: + * + * Hello! + * + * Note that depending on the widget that is used, it may be necessary to + * implement HasHTML instead of HasText. + * + * @param folderId the folder id + * @param isCreateConfiguration the is create configuration + */ + public ShowThreddsFolderInfoView(String folderId, boolean isCreateConfiguration) { + this.folderId = folderId; + this.isCreateConfiguration = isCreateConfiguration; + + initWidget(uiBinder.createAndBindUi(this)); + + pager.getLeft().addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + setError(false, ""); + submitHandler(SUBMIT_ACTION.CREATE_UPDATE_CONFIGURATION); + } + }); + + pager.getRight().addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + setError(false, ""); + //boolean isValid = validateSubmit(); + //if(isValid) + submitHandler(SUBMIT_ACTION.DO_SYNC); + + } + }); + + if(isCreateConfiguration) { + WsThreddsWidget.wsThreddsSyncService.getListOfVREsForLoggedUser(new AsyncCallback>() { + + @Override + public void onSuccess(List 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 + + } + }); + } + + } + + /** + * Update view to result. + * + * @param folder the folder + * @param syncFolderDesc the sync folder desc + */ + public void updateViewToResult(WsFolder folder, WsThreddsSynchFolderDescriptor syncFolderDesc) { + + this.field_select_vre.clear(); + + if(syncFolderDesc==null) { + pager.getRight().setVisible(false); + return; + } + + if(syncFolderDesc.getSyncStatus()!=null) { + this.field_folder_status.setValue(syncFolderDesc.getSyncStatus().toString()); + } + + if(syncFolderDesc.getSelectedVRE()!=null) { + this.field_select_vre.addItem(syncFolderDesc.getSelectedVRE().getVreScope(), syncFolderDesc.getSelectedVRE().getVreName()); + this.field_select_vre.setValue(0, syncFolderDesc.getSelectedVRE().getVreName()); + this.field_select_vre.setSelectedValue(syncFolderDesc.getSelectedVRE().getVreName()); + } + + ThSyncFolderDescriptor sfd = syncFolderDesc.getServerFolderDescriptor(); + if(sfd!=null) { + + this.field_folder_path.setValue(sfd.getFolderPath()); + this.field_folder_path.setTitle(sfd.getFolderPath()); + this.field_folder_locked.setValue(sfd.isLocked()+""); + + ThSynchFolderConfiguration config = sfd.getConfiguration(); + + if(config!=null) { + this.field_catalogue_name.setValue(config.getToCreateCatalogName()); + this.field_catalogue_name.setTitle(config.getToCreateCatalogName()); + this.field_remote_path.setValue(config.getRemotePath()); + this.field_remote_path.setTitle(config.getRemotePath()); + } + + + ThProcessDescriptor lpd = sfd.getLocalProcessDescriptor(); + if(lpd!=null) { + //this.field_last_sync.setValue(DateTimeFormat.getFormat(DATE_FORMAT_YYYY_MM_DD_HH_MM_SS).format(new Date(lpd.getLaunchTime()))); + ThSynchFolderConfiguration sc = lpd.getSynchConfiguration(); + if(sc!=null) { + + //this.field_select_vre.setValue(sc.get, value); + + } + } + } + } + + public boolean isCreateConfiguration() { + return isCreateConfiguration; + } + + + + /** + * Validate submit. + * + * @return true, if successful + */ + 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_catalogue_name.setType(ControlGroupType.ERROR); + setError(true, "Unit Title field is required"); + return false; + } + + if(field_remote_path.getValue()==null || field_remote_path.getValue().isEmpty()){ + cg_remote_path.setType(ControlGroupType.ERROR); + setError(true, "Folder Name field is required"); + return false; + } + + return true; + } + + + /** + * Gets the remote path. + * + * @return the remote path + */ + public String getRemotePath() { + return field_remote_path.getValue(); + } + + /** + * Gets the catalogue name. + * + * @return the catalogue name + */ + public String getCatalogueName(){ + return field_catalogue_name.getValue(); + } + + + /** + * Gets the unit description. + * + * @return the unit description + */ + public GcubeVRE getSelectedVRE(){ + String item = field_select_vre.getSelectedItemText(); + String text = field_select_vre.getSelectedValue(); + return mapVREs.get(item); + } + + + public Pager getPager() { + return pager; + } + + public HTMLPanel getMainPanel(){ + return form_unit_fields; + } + + + +} diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/ShowThreddsFolderInfoView.ui.xml b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/ShowThreddsFolderInfoView.ui.xml new file mode 100644 index 0000000..8cdc7b7 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/client/view/binder/ShowThreddsFolderInfoView.ui.xml @@ -0,0 +1,71 @@ + + + + .noBorder { + border: 0px; + } + + + + + + + Sync Status + + + + + + Folder Path + + + + + + Locked + + + + + + Catalogue Name + + + + + + + Published in the VRE + + + + + + + + Remote Path + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/public/WsThreddsWidget.css b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/public/WsThreddsWidget.css new file mode 100644 index 0000000..59650c7 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/public/WsThreddsWidget.css @@ -0,0 +1,8 @@ +/** Add css rules here for your application. */ + +.ws-thredds-modal-body div.modal-body { + position: relative; + max-height: 600px !important; + padding: 15px; + overflow-y: auto; +} diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/BeanConverter.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/BeanConverter.java new file mode 100644 index 0000000..1afedf0 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/BeanConverter.java @@ -0,0 +1,85 @@ +package org.gcube.portlets.widgets.wsthreddssync.server; + +import static org.gcube.common.authorization.client.Constants.authorizationService; + +import org.gcube.common.authorization.library.AuthorizationEntry; +import org.gcube.portal.wssynclibrary.shared.thredds.Sync_Status; +import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor; +import org.gcube.portal.wssynclibrary.shared.thredds.ThSynchFolderConfiguration; +import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeVRE; +import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderConfiguration; +import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescriptor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +// TODO: Auto-generated Javadoc +/** + * The Class BeanConverter. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Feb 16, 2018 + */ +public class BeanConverter { + + private static Logger logger = LoggerFactory.getLogger(BeanConverter.class); + + /** + * To ws thredds folder config. + * + * @param t the t + * @param theStatus the the status + * @return the ws thredds synch folder descriptor + */ + public static WsThreddsSynchFolderDescriptor toWsThreddsFolderConfig(ThSyncFolderDescriptor t, Sync_Status theStatus) { + + if(t==null) + return null; + + WsThreddsSynchFolderDescriptor ws = new WsThreddsSynchFolderDescriptor(); + ws.setServerFolderDescriptor(t); + ws.setSyncStatus(theStatus); + + //FROM TARGET TOKEN TO SCOPE + //t.getConfiguration().getTargetToken() + + if(t.getConfiguration().getTargetToken()!=null) { + try { + AuthorizationEntry entry = authorizationService().get(t.getConfiguration().getTargetToken()); + String scope = entry.getContext(); + GcubeVRE selectedVRE = new GcubeVRE(scope, scope); + ws.setSelectedVRE(selectedVRE); + logger.debug("Resolved VRE: "+selectedVRE +" from token"); + }catch (Exception e) { + // TODO: handle exception + } + } + + + + return ws; + + }; + + /** + * To th synch folder configuration. + * + * @param t the t + * @param targetScopeUserToken the target scope user token + * @return the th synch folder configuration + */ + public static ThSynchFolderConfiguration toThSynchFolderConfiguration(WsThreddsSynchFolderConfiguration t, String targetScopeUserToken) { + + if(t==null) + return null; + + ThSynchFolderConfiguration ts = new ThSynchFolderConfiguration(); + ts.setFilter(t.getFilter()); + ts.setRemotePath(t.getRemotePath()); + ts.setTargetToken(targetScopeUserToken); + ts.setToCreateCatalogName(t.getCatalogName()); + return ts; + + }; + +} diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SessionUtil.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SessionUtil.java new file mode 100644 index 0000000..d97567c --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SessionUtil.java @@ -0,0 +1,91 @@ +package org.gcube.portlets.widgets.wsthreddssync.server; + +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.http.HttpSession; + +import org.gcube.portlets.widgets.wsthreddssync.shared.TransferOnThreddsReport; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SessionUtil { + + private static Logger logger = LoggerFactory.getLogger(SessionUtil.class); + + public static final String FOLDER_SYNCRONIZE_WITH_THREDDS = "Folder_Syncronize_With_Thredds"; + + /** + * Sets the folder publishing on thredds. + * + * @param session the session + * @param report the report + */ + public static void setTransferPublishingOnThredds(HttpSession session, TransferOnThreddsReport report){ + + Map map = getMapTransferPublishingOnThredds(session); + + if(map!=null) + map.put(report.getTransferId(), report); + } + + + /** + * Gets the folder publishing on thredds. + * + * @param session the session + * @return the folder publishing on thredds + */ + public static Map getMapTransferPublishingOnThredds(HttpSession session){ + + Map map = null; + try{ + + map = (Map) session.getAttribute(FOLDER_SYNCRONIZE_WITH_THREDDS); + + if(map==null){ + logger.info("Creating new map to trace syncronize with thredds... "); + map = new HashMap(); + session.setAttribute(FOLDER_SYNCRONIZE_WITH_THREDDS, map); + } + + }catch (Exception e) { + logger.error("an error occurred instancing PropertySpecialFolderReader ",e); + } + + return map; + + } + + + /** + * Ge transfer publishing on thredds for id. + * + * @param session the session + * @param transferId the transfer id + * @return the transfer on thredds report + */ + public static TransferOnThreddsReport geTransferPublishingOnThreddsForId(HttpSession session, String transferId){ + + Map map = getMapTransferPublishingOnThredds(session); + + if(map!=null){ + return map.get(transferId); + } + + return null; + + } + + + /** + * Prints the as sys out. + * + * @param txt the txt + */ + public static void printAsSysOut(String txt) { + + System.out.println(txt); + } + +} diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java new file mode 100644 index 0000000..17b6e5e --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/SyncronizeWithThredds.java @@ -0,0 +1,207 @@ +/** + * + */ +package org.gcube.portlets.widgets.wsthreddssync.server; + +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.ThSyncFolderDescriptor; +import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus; +import org.gcube.portal.wssynclibrary.shared.thredds.ThSynchFolderConfiguration; +import org.gcube.portal.wssynclibrary.thredds.WorkspaceThreddsSynchronize; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + + +// TODO: Auto-generated Javadoc +/** + * The Class SyncronizeWithThredds. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Feb 7, 2018 + */ +public class SyncronizeWithThredds { + + + /** The logger. */ + private Logger logger = LoggerFactory.getLogger(SyncronizeWithThredds.class); + + /** The workspace thredds synchronize. */ + private WorkspaceThreddsSynchronize workspaceThreddsSynchronize; + + /** The Constant sdf. */ + //private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss"); + + + /** + * Instantiates a new publish on thredds. + * + * @param wsScopeUserToken the ws scope user token + * @param username the username + * @param httpSession the http session + */ + public SyncronizeWithThredds() { + this.workspaceThreddsSynchronize = WorkspaceThreddsSynchronize.getInstance(); + } + + + /** + * Sets the context parameters. + * + * @param scope the scope + * @param userToken the user token + */ + private void setContextParameters(String scope, String userToken) { + logger.debug("Setting context parameters, scope: "+scope +", user token: "+userToken); + ScopeProvider.instance.set(scope); + SecurityTokenProvider.instance.set(userToken); + } + + + /** + * Do sync folder. + * + * @param folderId the folder id + * @param thConfig the th config + * @param scope the scope + * @param userToken the user token + * @return the th sync status + * @throws Exception the exception + */ + 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); + }catch (ItemNotSynched e) { + firstSync = true; + // TODO: handle exception + }catch (Exception e) { + 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. + * + * @param folderId the folder id + * @param scope the scope + * @param username the username + * @return the synched status from item property + * @throws Exception the exception + */ + public Sync_Status getSynchedStatusFromItemProperty(String folderId, String scope, String username) throws Exception{ + + try { + try { + ScopeProvider.instance.set(scope); + return workspaceThreddsSynchronize.getSynchedStatusFromItemProperty(folderId, username); + }catch (ItemNotSynched e) { + 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"); + } + } + + + /** + * Checks if is item synched. + * + * @param folderId the folder id + * @param scope the scope + * @param username the username + * @return true, if is item synched + * @throws ItemNotSynched the item not synched + * @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; + } + + + /** + * Check item synched. + * + * @param folderId the folder id + * @param scope the scope + * @param userToken the user token + * @return the th sync folder descriptor + * @throws ItemNotSynched the item not synched + * @throws Exception the exception + */ + public ThSyncFolderDescriptor checkItemSynched(String folderId, String scope, String userToken) throws ItemNotSynched, Exception{ + + setContextParameters(scope, userToken); + return workspaceThreddsSynchronize.checkItemSynched(folderId); + } + + /** + * Gets the sync status. + * + * @param itemId the item id + * @param scope the scope + * @param userToken the user token + * @return the sync status + * @throws ItemNotSynched the item not synched + * @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 + */ + public void registerCallbackForId(String folderId, String scope, String userToken) throws Exception { + setContextParameters(scope, userToken); + workspaceThreddsSynchronize.registerCallbackForId(folderId); + } + +} diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java new file mode 100644 index 0000000..2b8adcd --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/ThreddsWorkspaceSyncServiceImpl.java @@ -0,0 +1,231 @@ +package org.gcube.portlets.widgets.wsthreddssync.server; + +import java.util.ArrayList; +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.ThSyncFolderDescriptor; +import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus; +import org.gcube.portal.wssynclibrary.shared.thredds.ThSynchFolderConfiguration; +import org.gcube.portlets.widgets.wsthreddssync.client.rpc.ThreddsWorkspaceSyncService; +import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeVRE; +import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderConfiguration; +import org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescriptor; +import org.gcube.vomanagement.usermanagement.GroupManager; +import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault; +import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException; +import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault; +import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager; +import org.gcube.vomanagement.usermanagement.model.GCubeGroup; +import org.gcube.vomanagement.usermanagement.model.GCubeUser; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.gwt.user.server.rpc.RemoteServiceServlet; +import com.liferay.portal.service.UserLocalServiceUtil; + +// TODO: Auto-generated Javadoc +/** + * The server side implementation of the RPC service. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Feb 14, 2018 + */ +@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; + + /** + * Gets the sync service. + * + * @return the sync service + */ + public synchronized SyncronizeWithThredds getSyncService() { + + if(syncThredds==null) + syncThredds = new SyncronizeWithThredds(); + + return syncThredds; + + } + + /** + * Checks if is within portal. + * + * @return true if you're running into the portal, false if in development + */ + public static boolean isWithinPortal() { + try { + UserLocalServiceUtil.getService(); + return true; + } + catch (Exception ex) { + logger.trace("Development Mode ON"); + return false; + } + } + + + + /** + * Do sync folder. + * + * @param folderId the folder id + * @param clientConfig the th config + * @return the th sync status + * @throws Exception the exception + */ + /* (non-Javadoc) + * @see org.gcube.portlets.widgets.wsthreddssync.client.rpc.ThreddsWorkspaceSyncService#doSyncFolder(java.lang.String, org.gcube.portlets.widgets.wsthreddssync.shared.WsThreddsSynchFolderDescriptor) + */ + @Override + public ThSyncStatus doSyncFolder(final String folderId, WsThreddsSynchFolderConfiguration clientConfig) throws Exception{ + logger.info("Performing doSyncFolder method on id: "+folderId +", config: "+clientConfig); + +// String scope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest()); +// GCubeUser username = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); +// String groupName = PortalContext.getConfiguration().getCurrentGroupName(this.getThreadLocalRequest()); +// new GcubeVRE(groupName, scope) + try { + GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); + //String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest()); + //String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername()); + String targetScopeUserToken = null; + ThSynchFolderConfiguration config = null; + if(clientConfig!=null) { + targetScopeUserToken = PortalContext.getConfiguration().getCurrentUserToken(clientConfig.getTheVRE().getVreScope(), user.getUsername()); + 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 list of VR es for logged user. + * + * @return the list of VR es for logged user + * @throws Exception the exception + */ + @Override + public List getListOfVREsForLoggedUser() throws Exception{ + logger.debug("getListOfVREsForLoggedUser...: "); + SessionUtil.printAsSysOut("\n\n\n\n getListOfVREsForLoggedUser"); + //PortalContextInfo context = WsUtil.getPortalContext(this.getThreadLocalRequest()); + GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); + long userId = user.getUserId(); + + // Instanciate the manager + GroupManager groupManager = new LiferayGroupManager(); + List listOfVres = new ArrayList(); + + if (!isWithinPortal()){ + listOfVres.add(new GcubeVRE("devVRE", "/gcube/devsec/devVRE")); + listOfVres.add(new GcubeVRE("NextNext", "/gcube/devNext/NextNext")); + return listOfVres; + } + + try { + + List listOfGroups = groupManager.listGroupsByUser(userId); + for (GCubeGroup gCubeGroup : listOfGroups) { + if(groupManager.isVRE(gCubeGroup.getGroupId())){ + GcubeVRE gcubeVRE = new GcubeVRE(gCubeGroup.getGroupName(), groupManager.getInfrastructureScope(gCubeGroup.getGroupId())); + listOfVres.add(gcubeVRE); + } + } + + } + catch (UserRetrievalFault | UserManagementSystemException + | GroupRetrievalFault e) { + logger.error("Error occurred server-side getting VRE folders: ", e); + throw new Exception("Sorry, an error occurred server-side getting VRE folders, try again later"); + } + + logger.info("Returning list of VREs: "+listOfVres); + return listOfVres; + } + + + + + /* (non-Javadoc) + * @see org.gcube.portlets.widgets.wsthreddssync.client.rpc.ThreddsWorkspaceSyncService#isItemSynched(java.lang.String) + */ + @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()); + ThSyncFolderDescriptor serverFolderSync = getSyncService().checkItemSynched(folderId,wsScope,wsUserToken); + WsThreddsSynchFolderDescriptor toWsThreddFolder = BeanConverter.toWsThreddsFolderConfig(serverFolderSync, theStatus); + 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; + }catch (Exception e) { + logger.info("Error on isItemSynched for folderId: "+folderId, e); + throw new Exception(e); + } + } + + + /** + * Register callback for id. + * + * @param folderId the folder id + * @throws Exception the exception + */ + public void registerCallbackForId(String folderId) throws Exception{ + GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); + String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest()); + String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername()); + getSyncService().registerCallbackForId(folderId, wsScope, wsUserToken); + } + + + /* (non-Javadoc) + * @see org.gcube.portlets.widgets.wsthreddssync.client.rpc.ThreddsWorkspaceSyncService#monitorSyncStatus(java.lang.String) + */ + @Override + public ThSyncStatus monitorSyncStatus(String folderId) throws ItemNotSynched, Exception{ + GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); + String wsScope = PortalContext.getConfiguration().getCurrentScope(this.getThreadLocalRequest()); + String wsUserToken = PortalContext.getConfiguration().getCurrentUserToken(wsScope, user.getUsername()); + return getSyncService().monitorSyncStatus(folderId, wsScope, wsUserToken); + } + + +} diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/WsUtil.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/WsUtil.java new file mode 100644 index 0000000..34c0073 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/WsUtil.java @@ -0,0 +1,85 @@ +/** + * + */ +package org.gcube.portlets.widgets.wsthreddssync.server; + +import javax.servlet.http.HttpServletRequest; + +import org.gcube.common.homelibrary.home.HomeLibrary; +import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException; +import org.gcube.common.homelibrary.home.exceptions.InternalErrorException; +import org.gcube.common.homelibrary.home.workspace.Workspace; +import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException; +import org.gcube.common.portal.PortalContext; +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.vomanagement.usermanagement.model.GCubeUser; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.liferay.portal.service.UserLocalServiceUtil; + + +/** + * The Class WsUtil. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Nov 25, 2016 + */ +public class WsUtil { + + private static Logger logger = LoggerFactory.getLogger(WsUtil.class); + + + /** + * Checks if is within portal. + * + * @return true if you're running into the portal, false if in development + */ + public static boolean isWithinPortal() { + try { + UserLocalServiceUtil.getService(); + return true; + } + catch (Exception ex) { + logger.trace("Development Mode ON"); + return false; + } + } + + + /** + * Checks if is session expired. + * + * @param httpServletRequest the http servlet request + * @return true, if is session expired + * @throws Exception the exception + */ + public static boolean isSessionExpired(HttpServletRequest httpServletRequest) throws Exception { + logger.trace("workspace session validating..."); + return PortalContext.getConfiguration().getCurrentUser(httpServletRequest)==null; + } + + + /** + * Gets the workspace. + * + * @param httpServletRequest the http servlet request + * @return the workspace + * @throws InternalErrorException the internal error exception + * @throws HomeNotFoundException the home not found exception + * @throws WorkspaceFolderNotFoundException the workspace folder not found exception + */ + public static Workspace getWorkspace(HttpServletRequest httpServletRequest) throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException + { + logger.trace("Get Workspace"); + String scope = PortalContext.getConfiguration().getCurrentScope(httpServletRequest); + GCubeUser user = PortalContext.getConfiguration().getCurrentUser(httpServletRequest); + + ScopeProvider.instance.set(scope); + logger.trace("Scope provider instancied at: "+scope); + + Workspace workspace = HomeLibrary.getUserWorkspace(user.getUsername()); + return workspace; + } + +} diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/FieldVerifier.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/FieldVerifier.java new file mode 100644 index 0000000..572c87a --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/FieldVerifier.java @@ -0,0 +1,42 @@ +package org.gcube.portlets.widgets.wsthreddssync.shared; + +/** + *

+ * FieldVerifier validates that the name the user enters is valid. + *

+ *

+ * This class is in the shared packing because we use it in both + * the client code and on the server. On the client, we verify that the name is + * valid before sending an RPC request so the user doesn't have to wait for a + * network round trip to get feedback. On the server, we verify that the name is + * correct to ensure that the input is correct regardless of where the RPC + * originates. + *

+ *

+ * When creating a class that is used on both the client and the server, be sure + * that all code is translatable and does not use native JavaScript. Code that + * is note translatable (such as code that interacts with a database or the file + * system) cannot be compiled into client side JavaScript. Code that uses native + * JavaScript (such as Widgets) cannot be run on the server. + *

+ */ +public class FieldVerifier { + + /** + * Verifies that the specified name is valid for our service. + * + * In this example, we only require that the name is at least four + * characters. In your application, you can use more complex checks to ensure + * that usernames, passwords, email addresses, URLs, and other fields have the + * proper syntax. + * + * @param name the name to validate + * @return true if valid, false if invalid + */ + public static boolean isValidName(String name) { + if (name == null) { + return false; + } + return name.length() > 3; + } +} diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/GcubeVRE.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/GcubeVRE.java new file mode 100644 index 0000000..295f965 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/GcubeVRE.java @@ -0,0 +1,111 @@ +package org.gcube.portlets.widgets.wsthreddssync.shared; + + +import java.io.Serializable; + +import com.google.gwt.user.client.rpc.IsSerializable; + + +// TODO: Auto-generated Javadoc +/** + * The Class GcubeVRE. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Feb 14, 2018 + */ +public class GcubeVRE implements Serializable, IsSerializable{ + + + /** + * + */ + private static final long serialVersionUID = -6427520549519606384L; + + /** The vre name. */ + private String vreName; + + /** The vre scope. */ + private String vreScope; + + /** + * Instantiates a new gcube VRE. + */ + public GcubeVRE() { + + } + + /** + * Instantiates a new gcube VRE. + * + * @param vreName the vre name + * @param vreScope the vre scope + */ + public GcubeVRE(String vreName, String vreScope) { + + super(); + this.vreName = vreName; + this.vreScope = vreScope; + } + + /** + * Gets the vre name. + * + * @return the vreName + */ + public String getVreName() { + + return vreName; + } + + + /** + * Gets the vre scope. + * + * @return the vreScope + */ + public String getVreScope() { + + return vreScope; + } + + + /** + * Sets the vre name. + * + * @param vreName the vreName to set + */ + public void setVreName(String vreName) { + + this.vreName = vreName; + } + + + /** + * Sets the vre scope. + * + * @param vreScope the vreScope to set + */ + public void setVreScope(String vreScope) { + + this.vreScope = vreScope; + } + + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + + StringBuilder builder = new StringBuilder(); + builder.append("GcubeVRE [vreName="); + builder.append(vreName); + builder.append(", vreScope="); + builder.append(vreScope); + builder.append("]"); + return builder.toString(); + } + + + +} diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/TransferOnThreddsReport.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/TransferOnThreddsReport.java new file mode 100644 index 0000000..cafebf3 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/TransferOnThreddsReport.java @@ -0,0 +1,201 @@ +/** + * + */ +package org.gcube.portlets.widgets.wsthreddssync.shared; + +import java.io.Serializable; + +import com.google.gwt.user.client.rpc.IsSerializable; + + +// TODO: Auto-generated Javadoc +/** + * The Class TransferOnThreddsReport. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Feb 7, 2018 + */ +public class TransferOnThreddsReport implements Serializable, IsSerializable{ + + /** + * + */ + private static final long serialVersionUID = 326492579557983L; + + /** The transfer id. */ + private String transferId; + + /** The folder id. */ + private String folderId; + + /** The on error. */ + private Boolean onError = false; + + /** The report message. */ + private String reportMessage = null; + + /** The report created on workspace. */ + private Boolean reportCreatedOnWorkspace = false; + + /** + * Instantiates a new transfer on thredds report. + */ + public TransferOnThreddsReport() { + + } + + /** + * Instantiates a new transfer on thredds report. + * + * @param transferId the transfer id + * @param folderId the folder id + * @param onError the on error + * @param reportMessage the report message + */ + public TransferOnThreddsReport(String transferId, String folderId, Boolean onError, String reportMessage) { + + this.transferId = transferId; + this.folderId = folderId; + this.onError = onError; + this.reportMessage = reportMessage; + } + + /** + * Sets the report created on workspace. + * + * @param reportCreatedOnWorkspace the reportCreated to set + */ + public void setReportCreatedOnWorkspace(Boolean reportCreatedOnWorkspace) { + + this.reportCreatedOnWorkspace = reportCreatedOnWorkspace; + } + + + /** + * Checks if is transferring report available. + * + * @return the boolean + */ + public Boolean isTransferringReportAvailable() { + + return reportCreatedOnWorkspace; + } + + + /** + * Gets the transfer id. + * + * @return the transferId + */ + public String getTransferId() { + + return transferId; + } + + + /** + * Gets the folder id. + * + * @return the folderId + */ + public String getFolderId() { + + return folderId; + } + + + /** + * Gets the on error. + * + * @return the onError + */ + public Boolean isOnError() { + + return onError; + } + + + /** + * Sets the transfer id. + * + * @param transferId the transferId to set + */ + public void setTransferId(String transferId) { + + this.transferId = transferId; + } + + + /** + * Sets the folder id. + * + * @param folderId the folderId to set + */ + public void setFolderId(String folderId) { + + this.folderId = folderId; + } + + + /** + * Sets the on error. + * + * @param onError the onError to set + */ + public void setOnError(Boolean onError) { + + this.onError = onError; + } + + + + + + /** + * Gets the report message. + * + * @return the reportMessage + */ + public String getReportMessage() { + + return reportMessage; + } + + + /** + * Sets the report message. + * + * @param reportMessage the reportMessage to set + */ + public void setReportMessage(String reportMessage) { + + this.reportMessage = reportMessage; + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + + StringBuilder builder = new StringBuilder(); + builder.append("TransferOnThreddsReport [transferId="); + builder.append(transferId); + builder.append(", folderId="); + builder.append(folderId); + builder.append(", onError="); + builder.append(onError); + builder.append(", reportMessage="); + builder.append(reportMessage); + builder.append(", reportCreated="); + builder.append(reportCreatedOnWorkspace); + builder.append("]"); + return builder.toString(); + } + + + + + + +} diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/TransferToThreddsProperty.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/TransferToThreddsProperty.java new file mode 100644 index 0000000..b2f34f4 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/TransferToThreddsProperty.java @@ -0,0 +1,232 @@ +/** + * + */ +package org.gcube.portlets.widgets.wsthreddssync.shared; + +import java.io.Serializable; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + + + + +// TODO: Auto-generated Javadoc +/** + * The Class TransferToThreddsProperty. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Feb 7, 2018 + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlRootElement +public class TransferToThreddsProperty implements Serializable{ + + + /** The folder id. */ + private String folderId; + + /** The catalogue name. */ + private String catalogueName; + + /** The vre name. */ + private String vreName; + + /** The vre scope. */ + private String vreScope; + + /** The metadata folder id. */ + private String metadataFolderId; + + /** The metadata folder name. */ + private String metadataFolderName; + + + /** + * Instantiates a new transfering to thredds property. + */ + public TransferToThreddsProperty() { + + } + + /** + * Instantiates a new transfering to thredds property. + * + * @param folderId the folder id + * @param catalogueName the catalogue name + * @param vreName the vre name + * @param vreScope the vre scope + * @param metadataFolderId the metadata folder id + * @param metadataFolderName the metadata folder name + */ + public TransferToThreddsProperty( + String folderId, String catalogueName, String vreName, + String vreScope, String metadataFolderId, String metadataFolderName) { + + super(); + this.folderId = folderId; + this.catalogueName = catalogueName; + this.vreName = vreName; + this.vreScope = vreScope; + this.metadataFolderId = metadataFolderId; + this.metadataFolderName = metadataFolderName; + } + + + /** + * Gets the folder id. + * + * @return the folderId + */ + public String getFolderId() { + + return folderId; + } + + + /** + * Gets the catalogue name. + * + * @return the catalogueName + */ + public String getCatalogueName() { + + return catalogueName; + } + + + /** + * Gets the vre name. + * + * @return the vreName + */ + public String getVreName() { + + return vreName; + } + + + /** + * Gets the vre scope. + * + * @return the vreScope + */ + public String getVreScope() { + + return vreScope; + } + + + /** + * Gets the metadata folder id. + * + * @return the metadataFolderId + */ + public String getMetadataFolderId() { + + return metadataFolderId; + } + + + /** + * Gets the metadata folder name. + * + * @return the metadataFolderName + */ + public String getMetadataFolderName() { + + return metadataFolderName; + } + + + /** + * Sets the folder id. + * + * @param folderId the folderId to set + */ + public void setFolderId(String folderId) { + + this.folderId = folderId; + } + + + /** + * Sets the catalogue name. + * + * @param catalogueName the catalogueName to set + */ + public void setCatalogueName(String catalogueName) { + + this.catalogueName = catalogueName; + } + + + /** + * Sets the vre name. + * + * @param vreName the vreName to set + */ + public void setVreName(String vreName) { + + this.vreName = vreName; + } + + + /** + * Sets the vre scope. + * + * @param vreScope the vreScope to set + */ + public void setVreScope(String vreScope) { + + this.vreScope = vreScope; + } + + + /** + * Sets the metadata folder id. + * + * @param metadataFolderId the metadataFolderId to set + */ + public void setMetadataFolderId(String metadataFolderId) { + + this.metadataFolderId = metadataFolderId; + } + + + /** + * Sets the metadata folder name. + * + * @param metadataFolderName the metadataFolderName to set + */ + public void setMetadataFolderName(String metadataFolderName) { + + this.metadataFolderName = metadataFolderName; + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + + StringBuilder builder = new StringBuilder(); + builder.append("TransferToThreddsProperty [folderId="); + builder.append(folderId); + builder.append(", catalogueName="); + builder.append(catalogueName); + builder.append(", vreName="); + builder.append(vreName); + builder.append(", vreScope="); + builder.append(vreScope); + builder.append(", metadataFolderId="); + builder.append(metadataFolderId); + builder.append(", metadataFolderName="); + builder.append(metadataFolderName); + builder.append("]"); + return builder.toString(); + } + + +} diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/WsFolder.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/WsFolder.java new file mode 100644 index 0000000..61b45d6 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/WsFolder.java @@ -0,0 +1,63 @@ +package org.gcube.portlets.widgets.wsthreddssync.shared; + +import java.io.Serializable; + +import com.google.gwt.user.client.rpc.IsSerializable; + +public class WsFolder implements Serializable, IsSerializable{ + + /** + * + */ + private static final long serialVersionUID = 6165912778479858611L; + private String folderId; + private String foderName; + + + public WsFolder() { + } + + + + public WsFolder(String folderId, String foderName) { + this.folderId = folderId; + this.foderName = foderName; + } + + + + public String getFolderId() { + return folderId; + } + + + public void setFolderId(String folderId) { + this.folderId = folderId; + } + + + public String getFoderName() { + return foderName; + } + + + public void setFoderName(String foderName) { + this.foderName = foderName; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("WsFolder [folderId="); + builder.append(folderId); + builder.append(", foderName="); + builder.append(foderName); + builder.append("]"); + return builder.toString(); + } + + + + + +} diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/WsThreddsSynchFolderConfiguration.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/WsThreddsSynchFolderConfiguration.java new file mode 100644 index 0000000..0403a60 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/WsThreddsSynchFolderConfiguration.java @@ -0,0 +1,151 @@ +package org.gcube.portlets.widgets.wsthreddssync.shared; + +import java.io.Serializable; + +import org.gcube.portal.wssynclibrary.shared.thredds.Status; + + +// TODO: Auto-generated Javadoc +/** + * The Class WsThreddsSynchFolderConfiguration. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Feb 16, 2018 + */ +public class WsThreddsSynchFolderConfiguration implements Serializable{ + + + /** + * + */ + private static final long serialVersionUID = -1140248888970305126L; + + /** The remote path. */ + private String remotePath; + + private GcubeVRE theSelectedVRE; + + /** The filter. */ + private String filter; + + /** The to create catalog name. */ + private String catalogName; + + private Status status; //just for serialization + + + /** + * Instantiates a new ws thredds synch folder configuration. + */ + public WsThreddsSynchFolderConfiguration() { + // TODO Auto-generated constructor stub + } + + + /** + * Instantiates a new ws thredds synch folder configuration. + * + * @param remotePath the remote path + * @param theVRE the the VRE + * @param filter the filter + * @param catalogName the catalog name + * @param serverConf the server conf + */ + public WsThreddsSynchFolderConfiguration(String remotePath, GcubeVRE theVRE, String filter, String catalogName) { + super(); + this.remotePath = remotePath; + this.theSelectedVRE = theVRE; + this.filter = filter; + this.catalogName = catalogName; + } + + /** + * Gets the remote path. + * + * @return the remote path + */ + public String getRemotePath() { + return remotePath; + } + + /** + * Sets the remote path. + * + * @param remotePath the new remote path + */ + public void setRemotePath(String remotePath) { + this.remotePath = remotePath; + } + + /** + * Gets the the VRE. + * + * @return the the VRE + */ + public GcubeVRE getTheVRE() { + return theSelectedVRE; + } + + /** + * Sets the the VRE. + * + * @param theVRE the new the VRE + */ + public void setTheVRE(GcubeVRE theVRE) { + this.theSelectedVRE = theVRE; + } + + /** + * Gets the filter. + * + * @return the filter + */ + public String getFilter() { + return filter; + } + + /** + * Sets the filter. + * + * @param filter the new filter + */ + public void setFilter(String filter) { + this.filter = filter; + } + + /** + * Gets the catalog name. + * + * @return the catalog name + */ + public String getCatalogName() { + return catalogName; + } + + /** + * Sets the catalog name. + * + * @param catalogName the new catalog name + */ + public void setCatalogName(String catalogName) { + this.catalogName = catalogName; + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("WsThreddsSynchFolderDescriptor [remotePath="); + builder.append(remotePath); + builder.append(", theSelectedVRE="); + builder.append(theSelectedVRE); + builder.append(", filter="); + builder.append(filter); + builder.append(", catalogName="); + builder.append(catalogName); + builder.append("]"); + return builder.toString(); + } +} diff --git a/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/WsThreddsSynchFolderDescriptor.java b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/WsThreddsSynchFolderDescriptor.java new file mode 100644 index 0000000..156f1b6 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/wsthreddssync/shared/WsThreddsSynchFolderDescriptor.java @@ -0,0 +1,122 @@ +package org.gcube.portlets.widgets.wsthreddssync.shared; + +import java.io.Serializable; + +import org.gcube.portal.wssynclibrary.shared.thredds.Sync_Status; +import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor; + + +// TODO: Auto-generated Javadoc +/** + * The Class WsThreddsSynchFolderDescriptor. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Feb 20, 2018 + */ +public class WsThreddsSynchFolderDescriptor implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -5395986188613871699L; + + private GcubeVRE selectedVRE; + + private ThSyncFolderDescriptor serverFolderDescriptor; + + private Sync_Status syncStatus; + + /** + * Instantiates a new ws thredds synch folder configuration. + */ + public WsThreddsSynchFolderDescriptor() { + // TODO Auto-generated constructor stub + } + + /** + * Instantiates a new ws thredds synch folder descriptor. + * + * @param selectedVRE the selected VRE + * @param serverFolderDescriptor the server folder descriptor + * @param syncStatus the sync status + */ + public WsThreddsSynchFolderDescriptor(GcubeVRE selectedVRE, ThSyncFolderDescriptor serverFolderDescriptor, + Sync_Status syncStatus) { + super(); + this.selectedVRE = selectedVRE; + this.serverFolderDescriptor = serverFolderDescriptor; + this.syncStatus = syncStatus; + } + + /** + * Gets the selected VRE. + * + * @return the selected VRE + */ + public GcubeVRE getSelectedVRE() { + return selectedVRE; + } + + /** + * Sets the sync status. + * + * @param syncStatus + * the new sync status + */ + public void setSyncStatus(Sync_Status syncStatus) { + this.syncStatus = syncStatus; + } + + /** + * Gets the sync status. + * + * @return the sync status + */ + public Sync_Status getSyncStatus() { + return syncStatus; + } + + /** + * Sets the selected VRE. + * + * @param selectedVRE + * the new selected VRE + */ + public void setSelectedVRE(GcubeVRE selectedVRE) { + this.selectedVRE = selectedVRE; + } + + /** + * Gets the server folder descriptor. + * + * @return the server folder descriptor + */ + public ThSyncFolderDescriptor getServerFolderDescriptor() { + return serverFolderDescriptor; + } + + /** + * Sets the server folder descriptor. + * + * @param serverFolderDescriptor + * the new server folder descriptor + */ + public void setServerFolderDescriptor(ThSyncFolderDescriptor serverFolderDescriptor) { + this.serverFolderDescriptor = serverFolderDescriptor; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("WsThreddsSynchFolderDescriptor [selectedVRE="); + builder.append(selectedVRE); + builder.append(", serverFolderDescriptor="); + builder.append(serverFolderDescriptor); + builder.append(", syncStatus="); + builder.append(syncStatus); + builder.append("]"); + return builder.toString(); + } + + +} diff --git a/src/main/resources/org/gcube/portlets/widgets/wsthreddssync/WsThreddsWidget.gwt.xml b/src/main/resources/org/gcube/portlets/widgets/wsthreddssync/WsThreddsWidget.gwt.xml new file mode 100644 index 0000000..d7d2257 --- /dev/null +++ b/src/main/resources/org/gcube/portlets/widgets/wsthreddssync/WsThreddsWidget.gwt.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..9e6cbb7 --- /dev/null +++ b/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,24 @@ + + + + + + + + wsThreddsSyncServlet + org.gcube.portlets.widgets.wsthreddssync.server.ThreddsWorkspaceSyncServiceImpl + + + + wsThreddsSyncServlet + /WsThreddsWidget/wsthreddssync + + + + + WsThreddsWidget.html + + + diff --git a/src/main/webapp/WsThreddsWidget.css b/src/main/webapp/WsThreddsWidget.css new file mode 100644 index 0000000..301d705 --- /dev/null +++ b/src/main/webapp/WsThreddsWidget.css @@ -0,0 +1,44 @@ +/** Add css rules here for your application. */ + + +/** Example rules used by the template application (remove for your app) */ +h1 { + font-size: 2em; + font-weight: bold; + color: #777777; + margin: 40px 0px 70px; + text-align: center; +} + +.sendButton { + display: block; + font-size: 16pt; +} + +/** Most GWT widgets already have a style name defined */ +.gwt-DialogBox { + width: 400px; +} + +.dialogVPanel { + margin: 5px; +} + +.serverResponseLabelError { + color: red; +} + +/** Set ids using widget.getElement().setId("idOfElement") */ +#closeButton { + margin: 15px 6px 6px; +} + +/** Add css rules here for your application. */ + +.ws-thredds-modal-body div.modal-body { + position: relative; + max-height: 600px !important; + padding: 15px; + overflow-y: auto; +} + diff --git a/src/main/webapp/WsThreddsWidget.html b/src/main/webapp/WsThreddsWidget.html new file mode 100644 index 0000000..7c9c20d --- /dev/null +++ b/src/main/webapp/WsThreddsWidget.html @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + Web Application Starter Project + + + + + + + + + + + + + + + + + + + + + + +

Web Application Starter Project

+ + + + + + + + + + + + +
Please enter your name:
+ + diff --git a/src/test/java/org/gcube/portlets/widgets/wsthreddssync/TestWsThreddsEngine.java b/src/test/java/org/gcube/portlets/widgets/wsthreddssync/TestWsThreddsEngine.java new file mode 100644 index 0000000..a8c80df --- /dev/null +++ b/src/test/java/org/gcube/portlets/widgets/wsthreddssync/TestWsThreddsEngine.java @@ -0,0 +1,131 @@ +package org.gcube.portlets.widgets.wsthreddssync; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.util.concurrent.Semaphore; + +import org.gcube.common.homelibrary.home.HomeLibrary; +import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException; +import org.gcube.common.homelibrary.home.exceptions.InternalErrorException; +import org.gcube.common.homelibrary.home.exceptions.UserNotFoundException; +import org.gcube.common.homelibrary.home.workspace.Workspace; +import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder; +import org.gcube.common.homelibrary.home.workspace.exceptions.InsufficientPrivilegesException; +import org.gcube.common.homelibrary.home.workspace.exceptions.ItemAlreadyExistException; +import org.gcube.common.homelibrary.home.workspace.exceptions.ItemNotFoundException; +import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException; +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.common.scope.impl.ScopeBean; +import org.gcube.usecases.ws.thredds.SyncEngine; +import org.gcube.usecases.ws.thredds.engine.impl.ProcessDescriptor; +import org.gcube.usecases.ws.thredds.engine.impl.ProcessStatus; +import org.gcube.usecases.ws.thredds.faults.InternalException; +import org.gcube.usecases.ws.thredds.faults.ProcessNotFoundException; +import org.gcube.usecases.ws.thredds.faults.WorkspaceInteractionException; +import org.gcube.usecases.ws.thredds.faults.WorkspaceLockedException; +import org.gcube.usecases.ws.thredds.faults.WorkspaceNotSynchedException; +import org.gcube.usecases.ws.thredds.model.SyncOperationCallBack; +import org.gcube.usecases.ws.thredds.model.SynchFolderConfiguration; + + +// TODO: Auto-generated Javadoc +/** + * The Class TestWsThreddsEngine. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Feb 7, 2018 + */ +public class TestWsThreddsEngine { + + public static String DEFAULT_SCOPE = "/gcube/devsec"; //DEV +// public static String DEFAULT_SCOPE = "/d4science.research-infrastructures.eu/gCubeApps"; + public static String TEST_USER = "francesco.mangiacrapa"; + + public static String TEST_FOLDER_ID = ""; + + public static void main(String[] args) throws ProcessNotFoundException, InternalErrorException, WorkspaceInteractionException, InternalException, WorkspaceFolderNotFoundException, ItemNotFoundException, InsufficientPrivilegesException, ItemAlreadyExistException, HomeNotFoundException, UserNotFoundException, MalformedURLException, IOException { + + // GET ENGINE : SINGLETON INSTANCE + SyncEngine engine=SyncEngine.get(); + + + + Workspace ws = HomeLibrary + .getHomeManagerFactory() + .getHomeManager() + .getHome(TEST_USER) + .getWorkspace(); + + + //TEST INFO... + //TestCommons.setScope(); + ScopeBean scope = new ScopeBean(DEFAULT_SCOPE); + ScopeProvider.instance.set(scope.toString()); + WorkspaceFolder folder=(WorkspaceFolder) ws.getItem(TEST_FOLDER_ID); + + // FOLDER CONFIGURATION BEAN + //SynchFolderConfiguration config=TestCommons.getSynchConfig(); + + String filter = ""; + String remotePersistence = ""; + String remotePath = ""; + String targetToken = ""; + SynchFolderConfiguration config = new SynchFolderConfiguration(remotePath, filter, targetToken, remotePersistence); + + try { + //try to clean it up, first.. + System.out.println("Cleaning it up.."); + engine.unsetSynchronizedFolder(folder.getId(), false); + }catch(WorkspaceNotSynchedException e) { + // it was already cleared + }catch(WorkspaceLockedException e) { + engine.forceUnlock(folder.getId()); + engine.unsetSynchronizedFolder(folder.getId(), false); + } + + + try { + // WHEN OPENING A FOLDER, INVOKE CHECK TO UPDATE SYNCH STATUS + engine.check(folder.getId(), false); + }catch(WorkspaceNotSynchedException e) { + System.out.println("Folder not synched, configurin it.."); + engine.setSynchronizedFolder(config, folder.getId()); + }catch(WorkspaceLockedException e) { + System.out.println("Workspace locked, going to force unlock.."); // MAINLY FOR TEST PURPOSES, OR WHEN SOMETHIGN GOES WRONG.. USE CAUTIOUSLY + engine.forceUnlock(folder.getId()); + } + + // INVOKE SYNCHRONIZATION ON FOLDER + ProcessDescriptor descriptor=engine.doSync(folder.getId()); + + System.out.println("Obtained descriptor : "+descriptor); + + + SyncOperationCallBack syncCall = new SyncOperationCallBack() { + + @Override + public void onStep(ProcessStatus status, ProcessDescriptor descriptor) { + System.out.println("ON STEP : "+status+" "+descriptor); + System.out.println("LOG : \n"+ status.getLogBuilder().toString()); + if(status.getStatus().equals(ProcessStatus.Status.COMPLETED)) { + + //COMPLETED FARE REMOVE DALLA MAPPA + } + + } + }; + + // REGISTER CALLBACK TO MONITOR PROGRESS + engine.registerCallBack(folder.getId(), syncCall); + + + engine.check(folder.getId(), true); + + + // INVOKE WHEN PORTAL SHUTS DOWN TO FREE RESOURCES AND STOP SYNC PROCESSES + engine.shutDown(); + + } + + +} diff --git a/src/test/java/org/gcube/portlets/widgets/wsthreddssync/TestWsThreddsQuery.java b/src/test/java/org/gcube/portlets/widgets/wsthreddssync/TestWsThreddsQuery.java new file mode 100644 index 0000000..e0150da --- /dev/null +++ b/src/test/java/org/gcube/portlets/widgets/wsthreddssync/TestWsThreddsQuery.java @@ -0,0 +1,49 @@ +package org.gcube.portlets.widgets.wsthreddssync; + +import org.gcube.common.homelibrary.home.HomeLibrary; +import org.gcube.common.homelibrary.home.workspace.Properties; +import org.gcube.common.homelibrary.home.workspace.Workspace; +import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder; +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.portal.wssynclibrary.shared.ItemNotSynched; + +public class TestWsThreddsQuery { + + final static String folderId = "61ea6d91-4b09-43ec-91c4-b2fdb9b8c538"; + static String scope = "/gcube/devsec"; + static String username = "francesco.mangiacrapa"; + // NextNeext Francesco's Token + static String token = "89257623-0570-4fbe-a15b-458bb84f4902-98187548"; + public static final String WS_SYNCH_SYNCH_STATUS = "WS-SYNCH.SYNCH-STATUS"; + + public static void main(String[] args) { + + isItemSynched(); + + } + + public static void isItemSynched(){ + + try { + ScopeProvider.instance.set(scope); + + Workspace workspace = HomeLibrary.getUserWorkspace(username); + WorkspaceFolder folder = (WorkspaceFolder) workspace.getItem(folderId); + Properties properties = folder.getProperties(); + + if (properties == null || properties.getProperties() == null || properties.getProperties().size() == 0) { + throw new ItemNotSynched("No properties to read"); + } + + String wsSyncStatus = properties.getProperties().get(WS_SYNCH_SYNCH_STATUS); + System.out.println("Current: " + WS_SYNCH_SYNCH_STATUS + " has value: " + wsSyncStatus); + + //System.out.println("isSynched: " + isSynched); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + +} diff --git a/src/test/resources/org/gcube/portlets/widgets/wsthreddssync/WsThreddsWidgetJUnit.gwt.xml b/src/test/resources/org/gcube/portlets/widgets/wsthreddssync/WsThreddsWidgetJUnit.gwt.xml new file mode 100644 index 0000000..38bd4b4 --- /dev/null +++ b/src/test/resources/org/gcube/portlets/widgets/wsthreddssync/WsThreddsWidgetJUnit.gwt.xml @@ -0,0 +1,9 @@ + + + + + + + + +