Difference between revisions of "CSV Import Wizard"

From Gcube Wiki
Jump to: navigation, search
Line 52: Line 52:
 
       <url-pattern>/[[APPLICATION NAME]]/LocalUploadServlet</url-pattern>
 
       <url-pattern>/[[APPLICATION NAME]]/LocalUploadServlet</url-pattern>
 
     </servlet-mapping>
 
     </servlet-mapping>
 +
</source>
 +
 +
== Example of use ==
 +
 +
Here an example of use.
 +
You first have to register your CSV target. I suggest to call it on the init method of your servlet:
 +
<source lang="java5">
 +
CSVTargetRegistry.getInstance().add(new DemoCSVTarget());
 +
</source>
 +
 +
In our example we are registering the ''DemoCSVTarget'' target.
 +
 +
Then on the UI side:
 +
<source lang="java5">
 +
ImportWizard importWizard = new ImportWizard("DemoCSVTarget");
 +
importWizard.show();
 +
</source>
 +
We have created the ImportWizard using the target name as parameter.
 +
 +
If you want to listen the main events on the wizard you can add a WizardListener:
 +
<source lang="java5">
 +
importWizard.addListener(new WizardListener() {
 +
 +
@Override
 +
public void failed(Throwable throwable, String reason, String details) {
 +
System.out.println("FAILED reason: "+reason+" details: "+details+" throwable: "+throwable);
 +
}
 +
 +
@Override
 +
public void completed() {
 +
System.out.println("COMPLETED");
 +
}
 +
 +
@Override
 +
public void aborted() {
 +
System.out.println("ABORT");
 +
}
 +
});
 +
 
</source>
 
</source>

Revision as of 16:38, 5 October 2012

The CSV Import Wizard is a generic GWT widget for the import of a CSV file in a destination system. The widget has been developed using the GXT 2.2.x framework.

The CSV Import Wizard aims to help all the components that needs to integrate a CSV import procedure in their system.

The CSV import is made of those main steps:

  • the CSV file retrieving from a source like a local file system, a user workspace or an FTP site.
  • the definition of CSV parsing information like the presence of a header, the file encoding, the separator.
  • the final import in a target system like a service in the infrastructure or an FTP site.

The widget is pluggable to support different CSV sources and different target. A default local file system source is distributed with the widget.

A workspace source can be added through the CSV Import Wizard Workspace component.

Installation

In order to use the widget you need to perform those steps:

  1. add the widget library as project dependency
  2. add this entry to your <project>.gwt.xml file:
    <inherits name='org.gcube.portlets.user.csvimportwizard.CSVImportWizard'/>
  3. add those entries to your web.xml files:
    <servlet> 
     	<servlet-name>CSVImportService</servlet-name>
		<servlet-class>org.gcube.portlets.user.csvimportwizard.server.CSVImportServiceImpl</servlet-class>
    </servlet>
 
    <servlet-mapping>
       <servlet-name>CSVImportService</servlet-name>
       <url-pattern>/[[APPLICATION NAME]]/CSVImportService</url-pattern>
    </servlet-mapping>
 
    <servlet> 
     	<servlet-name>CSVServlet</servlet-name>
		<servlet-class>org.gcube.portlets.user.csvimportwizard.server.CSVServlet</servlet-class>
    </servlet>
 
    <servlet-mapping>
       <servlet-name>CSVServlet</servlet-name>
       <url-pattern>/[[APPLICATION NAME]]/CSVServlet</url-pattern>
    </servlet-mapping>

where [APPLICATION NAME] is your gwt application name.

If you want to use the local file system source you need to add also those lines:

 
    <servlet> 
     	<servlet-name>LocalUploadServlet</servlet-name>
	<servlet-class>org.gcube.portlets.user.csvimportwizard.server.local.LocalUploadServlet</servlet-class>
    </servlet>
 
    <servlet-mapping>
       <servlet-name>LocalUploadServlet</servlet-name>
       <url-pattern>/[[APPLICATION NAME]]/LocalUploadServlet</url-pattern>
    </servlet-mapping>

Example of use

Here an example of use. You first have to register your CSV target. I suggest to call it on the init method of your servlet:

	CSVTargetRegistry.getInstance().add(new DemoCSVTarget());

In our example we are registering the DemoCSVTarget target.

Then on the UI side:

	ImportWizard importWizard = new ImportWizard("DemoCSVTarget");
	importWizard.show();

We have created the ImportWizard using the target name as parameter.

If you want to listen the main events on the wizard you can add a WizardListener:

	importWizard.addListener(new WizardListener() {
 
		@Override
		public void failed(Throwable throwable, String reason, String details) {
			System.out.println("FAILED reason: "+reason+" details: "+details+" throwable: "+throwable);
		}
 
		@Override
		public void completed() {
			System.out.println("COMPLETED");
		}
 
		@Override
		public void aborted() {
			System.out.println("ABORT");
		}
	});