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
task/19600
Francesco Mangiacrapa 7 years ago
parent 5ddc436148
commit 6dd28cceb7

@ -1,13 +1,18 @@
<ReleaseNotes>
<Changeset component="org.gcube.portlets-user.workspace-portlet-tree.6-17-2"
date="2017-09-27">
<Change>Incident #9676: fixed. Removed check on get sub-folder public link when operation is performed by an administrator</Change>
<Changeset component="org.gcube.portlets-user.workspace-portlet-tree.6-18-0"
date="2017-09-29">
<Change>Feature #9760: WS-Thredds synch folder integration</Change>
</Changeset>
<Changeset component="org.gcube.portlets-user.workspace-portlet-tree.6-17-2"
date="2017-09-13">
<Change>Incident #9676: fixed. Removed check on get sub-folder public
link when operation is performed by an administrator</Change>
</Changeset>
<Changeset component="org.gcube.portlets-user.workspace-portlet-tree.6-17-1"
date="2017-07-10">
<Change>Added regex in order to remove list of chars when renaming or
creating new item. It is different for folder and item name</Change>
creating new item. It is different for folder and item name
</Change>
</Changeset>
<Changeset component="org.gcube.portlets-user.workspace-portlet-tree.6-17-0"
date="2017-05-22">

@ -10,7 +10,7 @@
<groupId>org.gcube.portlets.user</groupId>
<artifactId>workspace-tree-widget</artifactId>
<version>6.17.2-SNAPSHOT</version>
<version>6.18.0-SNAPSHOT</version>
<name>gCube Workspace Tree Widget</name>
<description>
gCube Workspace Tree Widget is a widget to navigate and interact with gCube Workspace
@ -20,6 +20,15 @@
<developerConnection>scm:https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/${project.artifactId}</developerConnection>
<url>http://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/${project.artifactId}</url>
</scm>
<!-- USED FROM ECLIPSELINK -->
<repositories>
<repository>
<id>eclipselink</id>
<url>http://maven.research-infrastructures.eu:8081/nexus/content/repositories/eclipselink/</url>
</repository>
</repositories>
<properties>
<!-- Convenience property to set the GWT version -->
<gwtVersion>2.7.0</gwtVersion>
@ -99,6 +108,13 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.11</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.usecases</groupId>
<artifactId>ws-thredds</artifactId>

@ -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<GcubeVRE> 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);
}

@ -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<TransferOnThreddsReport> 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<TransferOnThreddsReport> callback);
void getTransferToThreddsProperty(
String folderId, AsyncCallback<TransferToThreddsProperty> callback);
}

@ -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<GcubeVRE> vreStore = new ListStore<GcubeVRE>();
public static List<GcubeVRE> 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<TransferToThreddsProperty>() {
@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<String>();
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<TransferOnThreddsReport>() {
GWT.log("metadataFolderId: "+metadataFolderId);
AppControllerExplorer.rpcWorkspaceService.publishOnThreddsCatalogue(theFolderToPublish.getIdentifier(), metadataFolderId, vre.getName(), vre.getScope(), txtCatalogueName.getValue(), new AsyncCallback<TransferOnThreddsReport>() {
@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();
}
}

@ -2278,7 +2278,6 @@ public class GWTWorkspaceBuilder {
return null;
}
/**
* To version history.
*

@ -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<FileVersionModel> performOperationOnVersionedFile(
String fileId, List<String> 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<GWTWorkspaceItem> 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<GcubeVRE> getListOfVREsForLoggedUser() throws Exception{
workspaceLogger.debug("getListOfVREsForLoggedUser...: ");
@ -4182,12 +4208,10 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
GroupManager groupManager = new LiferayGroupManager();
List<GcubeVRE> listOfVres = new ArrayList<GcubeVRE>();
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<String, String> 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<String, String> 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<String, String> 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<String, String> 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);

@ -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;
}
}
}

@ -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();
}
}
Loading…
Cancel
Save