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-b396298e98cftask/19600
parent
5ddc436148
commit
6dd28cceb7
@ -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…
Reference in New Issue