From 6dd28cceb7cc741d70eeadcc5ff18823d2a6649a Mon Sep 17 00:00:00 2001 From: Francesco Mangiacrapa Date: Fri, 29 Sep 2017 15:58:12 +0000 Subject: [PATCH] Completed #9760: WS-Thredds synch folder integration git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@154741 82a268e6-3cf1-43bd-a215-b396298e98cf --- distro/changelog.xml | 13 +- pom.xml | 18 +- .../client/rpc/GWTWorkspaceService.java | 33 ++- .../client/rpc/GWTWorkspaceServiceAsync.java | 14 +- .../view/windows/DialogPublishOnThredds.java | 80 ++++++- .../workspace/server/GWTWorkspaceBuilder.java | 1 - .../server/GWTWorkspaceServiceImpl.java | 163 +++++++++++++- .../util/TransferringToThreddsUtil.java | 88 ++++++++ .../shared/TransferToThreddsProperty.java | 199 ++++++++++++++++++ 9 files changed, 579 insertions(+), 30 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/workspace/server/util/TransferringToThreddsUtil.java create mode 100644 src/main/java/org/gcube/portlets/user/workspace/shared/TransferToThreddsProperty.java diff --git a/distro/changelog.xml b/distro/changelog.xml index 24e2fb8..53a87a4 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -1,13 +1,18 @@ - - Incident #9676: fixed. Removed check on get sub-folder public link when operation is performed by an administrator + Feature #9760: WS-Thredds synch folder integration + + Incident #9676: fixed. Removed check on get sub-folder public + link when operation is performed by an administrator + Added regex in order to remove list of chars when renaming or - creating new item. It is different for folder and item name + creating new item. It is different for folder and item name + diff --git a/pom.xml b/pom.xml index cfdd467..b6b21d0 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.gcube.portlets.user workspace-tree-widget - 6.17.2-SNAPSHOT + 6.18.0-SNAPSHOT gCube Workspace Tree Widget gCube Workspace Tree Widget is a widget to navigate and interact with gCube Workspace @@ -20,6 +20,15 @@ scm:https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/${project.artifactId} http://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/${project.artifactId} + + + + + eclipselink + http://maven.research-infrastructures.eu:8081/nexus/content/repositories/eclipselink/ + + + 2.7.0 @@ -99,6 +108,13 @@ provided + + javax.xml.bind + jaxb-api + 2.2.11 + provided + + org.gcube.usecases ws-thredds diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceService.java b/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceService.java index 47a2076..631cb96 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceService.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceService.java @@ -25,6 +25,7 @@ import org.gcube.portlets.user.workspace.shared.PublicLink; import org.gcube.portlets.user.workspace.shared.ReportAssignmentACL; import org.gcube.portlets.user.workspace.shared.SessionExpiredException; import org.gcube.portlets.user.workspace.shared.TransferOnThreddsReport; +import org.gcube.portlets.user.workspace.shared.TransferToThreddsProperty; import org.gcube.portlets.user.workspace.shared.TrashContent; import org.gcube.portlets.user.workspace.shared.TrashOperationContent; import org.gcube.portlets.user.workspace.shared.UserBean; @@ -789,24 +790,36 @@ public interface GWTWorkspaceService extends RemoteService{ */ List getListOfVREsForLoggedUser() throws Exception; + /** - * @param folderToPublishId - * @param folderMetadataId - * @param vreScope - * @param catalogueName - * @return - * @throws Exception + * Publish on thredds catalogue. + * + * @param folderToPublishId the folder to publish id + * @param folderMetadataId the folder metadata id + * @param vreName the vre name + * @param vreScope the vre scope + * @param catalogueName the catalogue name + * @return the transfer on thredds report + * @throws Exception the exception */ TransferOnThreddsReport publishOnThreddsCatalogue( - String folderToPublishId, String folderMetadataId, String vreScope, + String folderToPublishId, String folderMetadataId, String vreName, String vreScope, String catalogueName) throws Exception; + /** - * @param transferId - * @return - * @throws Exception + * Gets the status of publishing on thredds catalogue. + * + * @param transferId the transfer id + * @return the status of publishing on thredds catalogue + * @throws Exception the exception */ TransferOnThreddsReport getStatusOfPublishingOnThreddsCatalogue(String transferId) throws Exception; + /** + * @param folderId + * @return + */ + TransferToThreddsProperty getTransferToThreddsProperty(String folderId); } diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceServiceAsync.java b/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceServiceAsync.java index 55a9090..418334e 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceServiceAsync.java @@ -27,6 +27,7 @@ import org.gcube.portlets.user.workspace.shared.GarbageItem; import org.gcube.portlets.user.workspace.shared.PublicLink; import org.gcube.portlets.user.workspace.shared.ReportAssignmentACL; import org.gcube.portlets.user.workspace.shared.TransferOnThreddsReport; +import org.gcube.portlets.user.workspace.shared.TransferToThreddsProperty; import org.gcube.portlets.user.workspace.shared.TrashContent; import org.gcube.portlets.user.workspace.shared.TrashOperationContent; import org.gcube.portlets.user.workspace.shared.UserBean; @@ -792,16 +793,27 @@ public interface GWTWorkspaceServiceAsync { * * @param folderToPublishId the folder to publish id * @param folderMetadataId the folder metadata id + * @param vreName the vre name * @param vreScope the vre scope * @param catalogueName the catalogue name * @param callback the callback */ void publishOnThreddsCatalogue( - String folderToPublishId, String folderMetadataId, String vreScope, + String folderToPublishId, String folderMetadataId, String vreName, String vreScope, String catalogueName, AsyncCallback callback); + /** + * Gets the status of publishing on thredds catalogue. + * + * @param transferId the transfer id + * @param callback the callback + * @return the status of publishing on thredds catalogue + */ void getStatusOfPublishingOnThreddsCatalogue( String transferId, AsyncCallback callback); + void getTransferToThreddsProperty( + String folderId, AsyncCallback callback); + } diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogPublishOnThredds.java b/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogPublishOnThredds.java index 19a16e1..a84ed9f 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogPublishOnThredds.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogPublishOnThredds.java @@ -11,11 +11,13 @@ import org.gcube.portlets.user.workspace.client.event.RefreshFolderEvent; import org.gcube.portlets.user.workspace.client.model.FileModel; import org.gcube.portlets.user.workspace.client.model.GcubeVRE; import org.gcube.portlets.user.workspace.shared.TransferOnThreddsReport; +import org.gcube.portlets.user.workspace.shared.TransferToThreddsProperty; import org.gcube.portlets.widgets.wsexplorer.client.notification.WorkspaceExplorerSelectNotification.WorskpaceExplorerSelectNotificationListener; import org.gcube.portlets.widgets.wsexplorer.client.select.WorkspaceExplorerSelectDialog; import org.gcube.portlets.widgets.wsexplorer.shared.Item; import com.extjs.gxt.ui.client.Style.HorizontalAlignment; +import com.extjs.gxt.ui.client.core.XDOM; import com.extjs.gxt.ui.client.event.BaseEvent; import com.extjs.gxt.ui.client.event.ButtonEvent; import com.extjs.gxt.ui.client.event.ComponentEvent; @@ -61,6 +63,9 @@ public class DialogPublishOnThredds extends Dialog { private ListStore vreStore = new ListStore(); public static List listOfVres = null; + private Label infoOnLoading = new Label(""); + + private DialogPublishOnThredds INSTANCE = this; /** @@ -71,7 +76,48 @@ public class DialogPublishOnThredds extends Dialog { public DialogPublishOnThredds(FileModel theFolderToPublish) { this.theFolderToPublish = theFolderToPublish; + infoOnLoading.setType(LabelType.INFO); + infoOnLoading.setVisible(true); + infoOnLoading.setText("Loading Configurations..."); initLayout(); + INSTANCE.enablePublish(false); + AppControllerExplorer.rpcWorkspaceService.getTransferToThreddsProperty(theFolderToPublish.getIdentifier(), new AsyncCallback() { + + @Override + public void onFailure(Throwable caught) { + GWT.log("Error on loading TransferToThreddsProperty: "+caught.getMessage()); + infoOnLoading.setVisible(false); + //initiFormFields(); + INSTANCE.enablePublish(true); + } + + @Override + public void onSuccess(TransferToThreddsProperty result) { + GWT.log("Loaded TransferToThreddsProperty: "+result); + //initiFormFields(); + + if(result!=null){ + txtCatalogueName.setValue(result.getCatalogueName()); + + for (GcubeVRE gvre : vreStore.getModels()) { + if(gvre.getScope().compareTo(result.getVreScope())==0){ + selectVRE.setValue(gvre); + break; + } + } + + if(result.getMetadataFolderId()!=null && result.getMetadataFolderName()!=null){ + + metadataFolder = new FileModel(result.getMetadataFolderId(), result.getMetadataFolderName(), true); + triggerFieldMetadataFolderName.setValue(metadataFolder.getName()); + } + } + + infoOnLoading.setVisible(false); + INSTANCE.enablePublish(true); + } + }); + } /** @@ -112,6 +158,7 @@ public class DialogPublishOnThredds extends Dialog { vreStore.add(listOfVres); } + /** * Instantiates a new dialog add folder and smart. */ @@ -135,6 +182,7 @@ public class DialogPublishOnThredds extends Dialog { this.getButtonById(Dialog.OK).setText("Publish"); this.getButtonById(Dialog.CANCEL).setText("Close"); // this.getButtonById(Dialog.CANCEL).setText("Reset"); + txtCatalogueName = new TextField(); txtCatalogueName.setEmptyText("Type a Name..."); txtCatalogueName.setAllowBlank(false); @@ -202,11 +250,13 @@ public class DialogPublishOnThredds extends Dialog { if (isValidForm()){ hide(); + GWT.log("metadataFolder: "+metadataFolder); + String metadataFolderId = metadataFolder!=null?metadataFolder.getIdentifier():null; GcubeVRE vre = selectVRE.getSelection().get(0); - - AppControllerExplorer.rpcWorkspaceService.publishOnThreddsCatalogue(theFolderToPublish.getIdentifier(), metadataFolderId, vre.getScope(), txtCatalogueName.getValue(), new AsyncCallback() { + GWT.log("metadataFolderId: "+metadataFolderId); + AppControllerExplorer.rpcWorkspaceService.publishOnThreddsCatalogue(theFolderToPublish.getIdentifier(), metadataFolderId, vre.getName(), vre.getScope(), txtCatalogueName.getValue(), new AsyncCallback() { @Override public void onFailure(Throwable caught) { @@ -230,7 +280,9 @@ public class DialogPublishOnThredds extends Dialog { } }); + setFocusWidget(txtCatalogueName); + add(infoOnLoading); add(txtCatalogueName); add(selectVRE); //add(browse); @@ -239,11 +291,25 @@ public class DialogPublishOnThredds extends Dialog { mandatory.setType(LabelType.INFO); //mandatory.getElement().getStyle().set("#FF0000"); add(mandatory); - //add(hp); - this.show(); } + + + /** + * Enable publish. + * + * @param enable the enable + */ + private void enablePublish(boolean enable){ + this.getButtonById(Dialog.OK).setEnabled(enable); + } + + /** + * Show result. + * + * @param result the result + */ public void showResult(TransferOnThreddsReport result){ @@ -259,6 +325,11 @@ public class DialogPublishOnThredds extends Dialog { } + /** + * Polling start. + * + * @param result the result + */ public void pollingStart(final TransferOnThreddsReport result){ showResult(result); @@ -351,6 +422,7 @@ public class DialogPublishOnThredds extends Dialog { }; navigator.addWorkspaceExplorerSelectNotificationListener(listener); + navigator.setZIndex(XDOM.getTopZIndex()+50); navigator.show(); } } diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceBuilder.java b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceBuilder.java index 299f1bc..8b06a95 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceBuilder.java +++ b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceBuilder.java @@ -2278,7 +2278,6 @@ public class GWTWorkspaceBuilder { return null; } - /** * To version history. * diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java index f587d48..fa9df6c 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java @@ -23,6 +23,7 @@ import org.gcube.common.homelibrary.home.Home; 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.Properties; import org.gcube.common.homelibrary.home.workspace.Workspace; import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder; import org.gcube.common.homelibrary.home.workspace.WorkspaceItem; @@ -70,6 +71,7 @@ import org.gcube.portlets.user.workspace.server.util.AclTypeComparator; import org.gcube.portlets.user.workspace.server.util.DifferenceBetweenInfoContactModel; import org.gcube.portlets.user.workspace.server.util.PortalContextInfo; import org.gcube.portlets.user.workspace.server.util.StringUtil; +import org.gcube.portlets.user.workspace.server.util.TransferringToThreddsUtil; import org.gcube.portlets.user.workspace.server.util.UserUtil; import org.gcube.portlets.user.workspace.server.util.WsUtil; import org.gcube.portlets.user.workspace.server.util.resource.PropertySpecialFolderReader; @@ -81,6 +83,7 @@ import org.gcube.portlets.user.workspace.shared.PublicLink; import org.gcube.portlets.user.workspace.shared.ReportAssignmentACL; import org.gcube.portlets.user.workspace.shared.SessionExpiredException; import org.gcube.portlets.user.workspace.shared.TransferOnThreddsReport; +import org.gcube.portlets.user.workspace.shared.TransferToThreddsProperty; import org.gcube.portlets.user.workspace.shared.TrashContent; import org.gcube.portlets.user.workspace.shared.TrashOperationContent; import org.gcube.portlets.user.workspace.shared.UserBean; @@ -4024,6 +4027,15 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT /* (non-Javadoc) * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#performOperationOnVersionedFile(java.lang.String, java.util.List, org.gcube.portlets.user.workspace.shared.WorkspaceVersioningOperation) */ + /** + * Perform operation on versioned file. + * + * @param fileId the file id + * @param olderVersionIDs the older version i ds + * @param operation the operation + * @return the list + * @throws Exception the exception + */ @Override public List performOperationOnVersionedFile( String fileId, List olderVersionIDs, @@ -4108,6 +4120,14 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT /* (non-Javadoc) * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getImagesForFolder(java.lang.String, java.lang.String) */ + /** + * Gets the images for folder. + * + * @param folderId the folder id + * @param currentImageId the current image id + * @return the images for folder + * @throws Exception the exception + */ @Override public List getImagesForFolder(String folderId, String currentImageId) throws Exception { @@ -4171,6 +4191,12 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT /* (non-Javadoc) * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getListOfVREsForLoggedUser() */ + /** + * 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{ workspaceLogger.debug("getListOfVREsForLoggedUser...: "); @@ -4182,12 +4208,10 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT GroupManager groupManager = new LiferayGroupManager(); List listOfVres = new ArrayList(); - if (isTestMode()){ listOfVres.add(new GcubeVRE("devVRE", "/gcube/devsec/devVRE")); listOfVres.add(new GcubeVRE("NextNext", "/gcube/devNext/NextNext")); return listOfVres; - } try { @@ -4216,23 +4240,51 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT * Publish on thredds catalogue. * * @param folderToPublishId the folder to publish id - * @param folderMetadataId the folder metadata id + * @param metadataFolderId the folder metadata id + * @param vreName the vre name * @param vreTargetScope the vre scope * @param catalogueName the catalogue name * @return the transfer on thredds report * @throws Exception the exception */ @Override - public TransferOnThreddsReport publishOnThreddsCatalogue(String folderToPublishId, String folderMetadataId, String vreTargetScope, String catalogueName) throws Exception{ - workspaceLogger.info("Publishing on thredds the folderId: "+folderToPublishId+", metafolderId: "+folderMetadataId +", vre target scope: "+vreTargetScope); - System.out.println("Publishing on thredds the folderId: "+folderToPublishId+", metafolderId: "+folderMetadataId +", vre target scope: "+vreTargetScope); + public TransferOnThreddsReport publishOnThreddsCatalogue(final String folderToPublishId, final String metadataFolderId, final String vreName, final String vreTargetScope, final String catalogueName) throws Exception{ + workspaceLogger.info("Publishing on thredds the folderId: "+folderToPublishId+", metadataFolderId: "+metadataFolderId +", vre target scope: "+vreTargetScope); 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 = PortalContext.getConfiguration().getCurrentUserToken(vreTargetScope, user.getUsername()); PublishOnThredds pub = new PublishOnThredds(wsUserToken, user.getUsername(), this.getThreadLocalRequest().getSession()); - return pub.publishFolder(folderToPublishId, folderMetadataId, targetScopeUserToken, catalogueName); + TransferOnThreddsReport report = pub.publishFolder(folderToPublishId, metadataFolderId, targetScopeUserToken, catalogueName); + workspaceLogger.debug("Report created: "+report); + + try{ + //SAVING THREDDS TRANSFERING CONFIGURATIONS + String metadataFolderName = null; + if(metadataFolderId!=null){ + Workspace ws = getWorkspace(); + WorkspaceItem metadataFolder = ws.getItem(metadataFolderId); + metadataFolderName = metadataFolder.getName(); + } + //System.out.println("metadataFolderName name: "+metadataFolderName); + String xmlProperties = TransferringToThreddsUtil.toXML(new TransferToThreddsProperty(folderToPublishId, catalogueName, vreName, vreTargetScope, metadataFolderId, metadataFolderName)); + workspaceLogger.debug("Transfer to Thredds xmlProperties is:"+ xmlProperties); + Map properties = getPropertiesForWorkspaceItemId(folderToPublishId); + + if(properties!=null){ + String key = TransferToThreddsProperty.class.getSimpleName(); + properties.put(key, xmlProperties); + workspaceLogger.info("Adding gcube property ["+key+ ", "+xmlProperties +"] to itemId: "+folderToPublishId); + setPropertiesForWorkspaceItemId(folderToPublishId, properties); + } + + }catch (Exception e) { + workspaceLogger.warn("Error adding the TransferToThreddsProperty to item: "+folderToPublishId, e); + } + + return report; + }catch(Exception e){ workspaceLogger.error("Error occurred server-side when transfer to Thredds: ", e); throw new Exception("Sorry, an error occurred server-side performing transfer to Thredds, try again later"); @@ -4240,6 +4292,100 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } + + + /** + * Gets the properties for workspace item id. + * + * @param itemId the item id + * @return the properties for workspace item id + */ + private Map getPropertiesForWorkspaceItemId(String itemId){ + + try{ + if(itemId==null || itemId.isEmpty()) + return null; + + Workspace ws = getWorkspace(); + WorkspaceItem workItem = ws.getItem(itemId); + Properties properties = workItem.getProperties(); + return properties.getProperties(); + }catch(Exception e){ + workspaceLogger.warn("Error on getting properties for item id: "+itemId, e); + return null; + } + + } + + + /** + * Sets the properties for workspace item id. + * + * @param itemId the item id + * @param properties the properties + */ + private void setPropertiesForWorkspaceItemId(String itemId, Map properties){ + + try{ + if(itemId==null || itemId.isEmpty()) + return; + + Workspace ws = getWorkspace(); + WorkspaceItem workItem = ws.getItem(itemId); + workItem.getProperties().addProperties(properties); + }catch(Exception e){ + workspaceLogger.warn("Error on setting properties for item id: "+itemId, e); + } + + } + + + /** + * Gets the transfer to thredds property read from folderId. + * + * @param folderId the folder id + * @return the transfer to thredds property + */ + @Override + public TransferToThreddsProperty getTransferToThreddsProperty(String folderId){ + workspaceLogger.debug("Performing getTransferToThreddsProperty for folderId: "+folderId); + try { + Map properties = getPropertiesForWorkspaceItemId(folderId); + workspaceLogger.trace("Properties are: "+properties); + + if(properties==null) + return null; + + String theXMLThreddsProperty = properties.get(TransferToThreddsProperty.class.getSimpleName()); + workspaceLogger.trace(TransferToThreddsProperty.class.getSimpleName() +" is: "+theXMLThreddsProperty); + if(theXMLThreddsProperty==null){ + workspaceLogger.info("Transfer To Thredds properties does not exist for the folder id: "+folderId +", returning null"); + return null; + } + + TransferToThreddsProperty theObject = TransferringToThreddsUtil.toObject(theXMLThreddsProperty); + + if(theObject.getMetadataFolderId()!=null){ + Workspace ws = getWorkspace(); + String metadataFolderName = null; + try{ + FolderItem metadataFolder = (FolderItem) ws.getItem(theObject.getMetadataFolderId()); + metadataFolderName = metadataFolder.getName(); + theObject.setMetadataFolderName(metadataFolderName); + }catch(Exception e){ + workspaceLogger.warn("Error on getting metadata folder name for id: "+metadataFolderName); + } + } + System.out.println("Returning: "+theObject); + workspaceLogger.debug("Returning: "+theObject); + return theObject; + } + catch (Exception e) { + workspaceLogger.error("Error occurred server-side when gettomg TransferToThreddsProperty for folderId: "+folderId, e); + return null; + } + } + /** * Gets the publishing on thredds catalogue. * @@ -4252,8 +4398,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT workspaceLogger.debug("Getting publishing on thredds for transfer id: "+transferId); TransferOnThreddsReport tr = null; try{ - tr = PublishOnThredds.getStatusOfTransferId(this.getThreadLocalRequest().getSession(), transferId); - return tr; + return PublishOnThredds.getStatusOfTransferId(this.getThreadLocalRequest().getSession(), transferId); }catch(Exception e){ workspaceLogger.error("Error occurred server-side when getting the status of transferring on Thredds: ", e); tr.setOnError(true); diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/util/TransferringToThreddsUtil.java b/src/main/java/org/gcube/portlets/user/workspace/server/util/TransferringToThreddsUtil.java new file mode 100644 index 0000000..5396118 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/workspace/server/util/TransferringToThreddsUtil.java @@ -0,0 +1,88 @@ +/** + * + */ +package org.gcube.portlets.user.workspace.server.util; + +import java.io.StringReader; +import java.io.UnsupportedEncodingException; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; +import javax.xml.transform.stream.StreamSource; + +import org.apache.commons.io.output.ByteArrayOutputStream; +import org.apache.log4j.Logger; +import org.gcube.portlets.user.workspace.shared.TransferToThreddsProperty; + + +/** + * The Class TransferringToThreddsUtil. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Sep 29, 2017 + */ +public class TransferringToThreddsUtil { + + public static Logger logger = Logger.getLogger(TransferringToThreddsUtil.class); + + + /** + * To xml. + * + * @param property the property + * @return the string + */ + public static String toXML(TransferToThreddsProperty property) { + logger.debug("Marshalling: "+property); + System.out.println("Marshalling: "+property); + try{ + // Create a JaxBContext + JAXBContext jc = JAXBContext.newInstance(TransferToThreddsProperty.class); + // Create the Marshaller Object using the JaxB Context + Marshaller marshaller = jc.createMarshaller(); + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + marshaller.marshal(property, baos); + String marshallingJsonString = baos.toString("UTF-8"); + //System.out.println("XML: "+marshallingJsonString); + return marshallingJsonString; + }catch(JAXBException | UnsupportedEncodingException e){ + logger.warn("Error during marshalling: "+property, e); + e.printStackTrace(); + return null; + } + + } + + /** + * Unmarshalling To OBJECT. + * + * @param xml the xml + * @return the transfering to thredds property + */ + public static TransferToThreddsProperty toObject(String xml){ + // Create a JaxBContext + JAXBContext jc; + try { + + jc = JAXBContext.newInstance(TransferToThreddsProperty.class); + + // Create the Unmarshaller Object using the JaxB Context + Unmarshaller unmarshaller = jc.createUnmarshaller(); + + // Create the StreamSource by creating StringReader using the JSON input + StreamSource stream = new StreamSource(new StringReader(xml)); + + // Getting the TransferingToThreddsProperty pojo again from the json + return unmarshaller.unmarshal(stream, TransferToThreddsProperty.class).getValue(); + + } + catch (JAXBException e) { + logger.warn("Error during unmarshalling: "+xml, e); + return null; + } + + } +} diff --git a/src/main/java/org/gcube/portlets/user/workspace/shared/TransferToThreddsProperty.java b/src/main/java/org/gcube/portlets/user/workspace/shared/TransferToThreddsProperty.java new file mode 100644 index 0000000..df6a682 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/workspace/shared/TransferToThreddsProperty.java @@ -0,0 +1,199 @@ +/** + * + */ +package org.gcube.portlets.user.workspace.shared; + +import java.io.Serializable; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + + + +/** + * The Class TransferToThreddsProperty. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Sep 29, 2017 + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlRootElement +public class TransferToThreddsProperty implements Serializable{ + + /** + * + */ + private static final long serialVersionUID = -7160662779647989154L; + + + private String folderId; + private String catalogueName; + private String vreName; + private String vreScope; + private String metadataFolderId; + 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 + */ + 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; + } + + + /** + * @return the folderId + */ + public String getFolderId() { + + return folderId; + } + + + /** + * @return the catalogueName + */ + public String getCatalogueName() { + + return catalogueName; + } + + + /** + * @return the vreName + */ + public String getVreName() { + + return vreName; + } + + + /** + * @return the vreScope + */ + public String getVreScope() { + + return vreScope; + } + + + /** + * @return the metadataFolderId + */ + public String getMetadataFolderId() { + + return metadataFolderId; + } + + + /** + * @return the metadataFolderName + */ + public String getMetadataFolderName() { + + return metadataFolderName; + } + + + /** + * @param folderId the folderId to set + */ + public void setFolderId(String folderId) { + + this.folderId = folderId; + } + + + /** + * @param catalogueName the catalogueName to set + */ + public void setCatalogueName(String catalogueName) { + + this.catalogueName = catalogueName; + } + + + /** + * @param vreName the vreName to set + */ + public void setVreName(String vreName) { + + this.vreName = vreName; + } + + + /** + * @param vreScope the vreScope to set + */ + public void setVreScope(String vreScope) { + + this.vreScope = vreScope; + } + + + /** + * @param metadataFolderId the metadataFolderId to set + */ + public void setMetadataFolderId(String metadataFolderId) { + + this.metadataFolderId = metadataFolderId; + } + + + /** + * @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(); + } + + +}