Skip to content

A domain service for use within Apache Isis, providing the ability to perform bulk export/import of collections of objects to/from an Excel spreadsheet.

License

Notifications You must be signed in to change notification settings

oscarbou/isis-module-excel

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

72 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

isis-module-excel

Build Status

This module, intended for use with Apache Isis, provides a domain service so that a collection of (view model) object scan be exported to an Excel spreadsheet, or recreated by importing from Excel.

The underlying technology used is Apache POI.

Screenshots

The following screenshots show an example app's usage of the module.

Installing the Fixture Data

The fixture data creates a set of todo items in various categories:

Exporting items using the (example) bulk update manager

The example app has a bulk update manager as a wrapper around the ExcelService:

The (example) bulk update manager allows the end-user to define a criteria to exporting a (sub)set of items:

which are then downloaded ...

... and can be viewed in Microsoft Excel:

Importing Exporting Excel

Using Excel the user can update data:

... and the use the (example) bulk update manager to import:

specifying the updated spreadsheet in the dialog:

View models represent the Excel rows

For each row in the spreadsheet the ExcelService instantiates a corresponding view model.

The view model can then provide a bulk apply action...

to update the corresponding entity:

How to run the Demo App

The prerequisite software is:

  • Java JDK 7 (nb: Isis currently does not support JDK 8)
  • maven 3 (3.2.x is recommended).

To build the demo app:

git clone https://github.com/isisaddons/isis-module-excel.git
mvn clean install

To run the demo app:

mvn antrun:run -P self-host

Then log on using user: sven, password: pass

How to configure/use

You can either use this module "out-of-the-box", or you can fork this repo and extend to your own requirements.

"Out-of-the-box"

To use "out-of-the-box":

  • update your classpath by adding this dependency in your dom project's pom.xml:
    <dependency>
        <groupId>org.isisaddons.module.excel</groupId>
        <artifactId>isis-module-excel-dom</artifactId>
        <version>1.8.0</version>
    </dependency>
  • update your WEB-INF/isis.properties:
    isis.services-installer=configuration-and-annotation
    isis.services.ServicesInstallerFromAnnotation.packagePrefix=
                    ...,\
                    org.isisaddons.module.excel,\
                    ...

Check for later releases by searching Maven Central Repo.

"Out-of-the-box" (-SNAPSHOT)

If you want to use the current -SNAPSHOT, then the steps are the same as above, except:

  • when updating the classpath, specify the appropriate -SNAPSHOT version:
    <version>1.9.0-SNAPSHOT</version>
  • add the repository definition to pick up the most recent snapshot (we use the Cloudbees continuous integration service). We suggest defining the repository in a <profile>:
    <profile>
        <id>cloudbees-snapshots</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <repositories>
            <repository>
                <id>snapshots-repo</id>
                <url>http://repository-estatio.forge.cloudbees.com/snapshot/</url>
                <releases>
                    <enabled>false</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </repository>
        </repositories>
    </profile>

Forking the repo

If instead you want to extend this module's functionality, then we recommend that you fork this repo. The repo is structured as follows:

  • pom.xml - parent pom
  • dom - the module implementation, depends on Isis applib
  • fixture - fixtures, holding a sample domain objects and fixture scripts; depends on dom
  • integtests - integration tests for the module; depends on fixture
  • webapp - demo webapp (see above screenshots); depends on dom and fixture

Only the dom project is released to Maven Central Repo. The versions of the other modules are purposely left at 0.0.1-SNAPSHOT because they are not intended to be released.

API

The API exposed by ExcelService is:

public class ExcelService {

    public static class Exception extends RuntimeException { ... }
    
    @Programmatic
    public <T> Blob toExcel(
        final List<T> domainObjects, 
        final Class<T> cls, 
        final String fileName) 
        throws ExcelService.Exception { ... }

    @Programmatic
    public <T extends ViewModel> List<T> fromExcel(
        final Blob excelBlob, 
        final Class<T> cls) 
        throws ExcelService.Exception { ... };
}

Usage

Given:

public class ToDoItemExportImportLineItem extends AbstractViewModel { ... }

which are wrappers around ToDoItem entities:

final List<ToDoItem> items = ...;
final List<ToDoItemExportImportLineItem> toDoItemViewModels = 
    Lists.transform(items, 
        new Function<ToDoItem, ToDoItemExportImportLineItem>(){
            @Override
            public ToDoItemExportImportLineItem apply(final ToDoItem toDoItem) {
                return container.newViewModelInstance(
                    ToDoItemExportImportLineItem.class, 
                    bookmarkService.bookmarkFor(toDoItem).getIdentifier());
            }
        });

then the following creates an Isis Blob (bytestream) containing the spreadsheet of these view models:

return excelService.toExcel(
         toDoItemViewModels, ToDoItemExportImportLineItem.class, fileName);

and conversely:

Blob spreadsheet = ...;
List<ToDoItemExportImportLineItem> lineItems = 
    excelService.fromExcel(spreadsheet, ToDoItemExportImportLineItem.class);

recreates view models from a spreadsheet.

Related Modules

See also the Excel wicket extension, which makes every collection downloadable as an Excel spreadsheet.

Change Log

  • 1.8.0 - released against Isis 1.8.0
  • 1.7.0 - released against Isis 1.7.0
  • 1.6.0 - re-released as part of isisaddons, with classes under package org.isisaddons.module.excel

Legal Stuff

License

Copyright 2014 Dan Haywood

Licensed under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.

Dependencies

In addition to Apache Isis, this module depends on:

  • org.apache.poi:poi (ASL v2.0 License)
  • org.apache.poi:poi-ooxml (ASL v2.0 License)
  • org.apache.poi:poi-ooxml-schemas (ASL v2.0 License)

Maven deploy notes

Only the dom module is deployed, and is done so using Sonatype's OSS support (see user guide).

Release to Sonatype's Snapshot Repo

To deploy a snapshot, use:

pushd dom
mvn clean deploy
popd

The artifacts should be available in Sonatype's Snapshot Repo.

Release to Maven Central

The release.sh script automates the release process. It performs the following:

  • performs a sanity check (mvn clean install -o) that everything builds ok
  • bumps the pom.xml to a specified release version, and tag
  • performs a double check (mvn clean install -o) that everything still builds ok
  • releases the code using mvn clean deploy
  • bumps the pom.xml to a specified release version

For example:

sh release.sh 1.9.0 \
              1.10.0-SNAPSHOT \
              [email protected] \
              "this is not really my passphrase"

where

  • $1 is the release version
  • $2 is the snapshot version
  • $3 is the email of the secret key (~/.gnupg/secring.gpg) to use for signing
  • $4 is the corresponding passphrase for that secret key.

Other ways of specifying the key and passphrase are available, see the pgp-maven-plugin's documentation).

If the script completes successfully, then push changes:

git push origin master
git push origin 1.9.0

If the script fails to complete, then identify the cause, perform a git reset --hard to start over and fix the issue before trying again. Note that in the dom's pom.xml the nexus-staging-maven-plugin has the autoReleaseAfterClose setting set to true (to automatically stage, close and the release the repo). You may want to set this to false if debugging an issue.

According to Sonatype's guide, it takes about 10 minutes to sync, but up to 2 hours to update search.

About

A domain service for use within Apache Isis, providing the ability to perform bulk export/import of collections of objects to/from an Excel spreadsheet.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 93.4%
  • HTML 3.4%
  • Shell 1.7%
  • CSS 1.5%