Difference between revisions of "CSV Import Wizard"
(→Installation of the Workspace extension) |
|||
Line 9: | Line 9: | ||
− | The widget is pluggable to support different CSV sources and different target. | + | The widget is pluggable to support different CSV sources and different import target. |
− | A default local file system source is distributed with the widget. A | + | === CSV Source === |
+ | A default local file system source is distributed with the widget. | ||
+ | A Workspace source can be added through the '''CSV Import Wizard Workspace''' component. | ||
+ | The [[Workspace]] Source use the [[WorkspaceLightTree|Workspace Light Tree]] to let the user select the item to import. | ||
+ | |||
+ | === CSV Target === | ||
The hosting application have to define his target in order to manage the import finalization. | The hosting application have to define his target in order to manage the import finalization. | ||
The '''CSVTarget''' interface is composed by two methods: | The '''CSVTarget''' interface is composed by two methods: |
Revision as of 15:55, 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 import target.
Contents
CSV Source
A default local file system source is distributed with the widget. A Workspace source can be added through the CSV Import Wizard Workspace component.
The Workspace Source use the Workspace Light Tree to let the user select the item to import.
CSV Target
The hosting application have to define his target in order to manage the import finalization. The CSVTarget interface is composed by two methods:
/** * Returns the target id. * @return */ public String getId(); /** * Start the CSV import. * @param csvFile the csv file. * @param parserConfiguration the parser configuration. * @param columnToImportMask a mask for column to import selection * @param operationProgress */ public void importCSV(File csvFile, CSVParserConfiguration parserConfiguration, boolean[] columnToImportMask, OperationProgress operationProgress);
The getId method returns the id that we need to pass to the ImportWizard constructor.
The importCSV method is called when the final step is reached. The interface implementation is in charge of updating the import progress state using the OperationProgress object.
Installation
In order to use the widget you need to perform those steps:
- add the widget library as project dependency
- add this entry to your <project>.gwt.xml file:
<inherits name='org.gcube.portlets.user.csvimportwizard.CSVImportWizard'/>
- 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>
Installation of the Workspace extension
To use the Wokspace extension you need to add this line to your gwt.xml file:<inherits name="org.gcube.portlets.user.csvimportwizard.ws.CSVImportWizardWorkspace" />
Then you have to add those lines to the web.xml file:
<!-- Servlets for CSV Import Wizard Workspace--> <servlet> <servlet-name>CSVImportServiceWorkspace</servlet-name> <servlet-class>org.gcube.portlets.user.csvimportwizard.ws.server.ImportWizardWSServiceImpl</servlet-class> </servlet> <servlet-mapping> <servlet-name>CSVImportServiceWorkspace</servlet-name> <url-pattern>/[APPLICATION NAME]/CSVImportServiceWorkspace</url-pattern> </servlet-mapping>
where [APPLICATION NAME] is your gwt application name.
Finally you have to modify the web.xml file in order to support the Workspace Light Tree as explained here.
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 id 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"); } });