dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #04420
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1468: Removed the LocationManagerResolver interace. Codestyle fixes.
------------------------------------------------------------
revno: 1468
committer: Lars Helge Oeverland <larshelge@xxxxxxxxx>
branch nick: trunk
timestamp: Mon 2010-02-22 16:25:35 +0100
message:
Removed the LocationManagerResolver interace. Codestyle fixes.
removed:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/external/location/LocationManagerResolver.java
modified:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormAssociationService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/hibernate/HibernateDataEntryFormAssociationStore.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/hibernate/HibernateDataEntryFormStore.java
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xml/importer/DefaultXMLImportService.java
dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/dxf/DXFImportServiceTest.java
dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/location/DefaultLocationManager.java
dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/location/DefaultLocationManagerResolver.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription.
=== removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/external/location/LocationManagerResolver.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/external/location/LocationManagerResolver.java 2010-02-19 18:38:02 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/external/location/LocationManagerResolver.java 1970-01-01 00:00:00 +0000
@@ -1,45 +0,0 @@
-package org.hisp.dhis.external.location;
-
-
-import javax.xml.transform.URIResolver;
-
-/*
- * Copyright (c) 2004-2005, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * * Neither the name of the <ORGANIZATION> nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/**
- * URI Resolver for xslt transforms based on LocationManager
- *
- * @author bobj
- * @version created 12-Feb-2010
- */
-public interface LocationManagerResolver extends URIResolver {
-
- LocationManager getLocationManager();
-
- void setLocationManager(LocationManager lm);
-
-}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormAssociationService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormAssociationService.java 2010-02-22 09:19:15 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormAssociationService.java 2010-02-22 15:25:35 +0000
@@ -38,9 +38,7 @@
import org.springframework.transaction.annotation.Transactional;
/**
- *
* @author Viet Nguyen
- *
*/
@Transactional
public class DefaultDataEntryFormAssociationService
@@ -118,7 +116,7 @@
{
return null;
}
+
return dataEntryFormAssociationStore.listDisctinctDataEntryFormByAssociationIds( associationName, associationIds );
}
-
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/hibernate/HibernateDataEntryFormAssociationStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/hibernate/HibernateDataEntryFormAssociationStore.java 2010-02-22 09:19:15 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/hibernate/HibernateDataEntryFormAssociationStore.java 2010-02-22 15:25:35 +0000
@@ -31,7 +31,6 @@
import java.util.List;
import org.hibernate.Criteria;
-import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Projections;
@@ -42,15 +41,11 @@
import org.springframework.orm.hibernate3.HibernateQueryException;
/**
- *
* @author Viet
- *
*/
-
public class HibernateDataEntryFormAssociationStore
implements DataEntryFormAssociationStore
{
-
// -------------------------------------------------------------------------
// Dependencies
// -------------------------------------------------------------------------
@@ -116,6 +111,7 @@
return (DataEntryFormAssociation) criteria.uniqueResult();
}
+ @SuppressWarnings( "unchecked" )
public Collection<DataEntryForm> listDisctinctDataEntryFormByAssociationIds(String associationName, List<Integer> associationIds )
{
Session session = sessionFactory.getCurrentSession();
@@ -125,5 +121,4 @@
.setProjection( Projections.distinct( Projections.property( "dataEntryForm" ) ) );
return criteria.list();
}
-
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/hibernate/HibernateDataEntryFormStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/hibernate/HibernateDataEntryFormStore.java 2010-02-22 09:19:15 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/hibernate/HibernateDataEntryFormStore.java 2010-02-22 15:25:35 +0000
@@ -28,7 +28,6 @@
*/
import java.util.Collection;
-import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Session;
=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xml/importer/DefaultXMLImportService.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xml/importer/DefaultXMLImportService.java 2010-02-19 18:38:02 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xml/importer/DefaultXMLImportService.java 2010-02-22 15:25:35 +0000
@@ -1,8 +1,5 @@
package org.hisp.dhis.importexport.xml.importer;
-
-import java.io.BufferedInputStream;
-
/*
* Copyright (c) 2004-2005, University of Oslo
* All rights reserved.
@@ -30,6 +27,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.io.BufferedInputStream;
+
import java.io.InputStream;
import java.util.Iterator;
import java.util.zip.GZIPInputStream;
@@ -42,7 +41,6 @@
import javax.xml.transform.Source;
import javax.xml.transform.URIResolver;
import javax.xml.transform.stax.StAXResult;
-import javax.xml.transform.stax.StAXSource;
import javax.xml.transform.stream.StreamSource;
import org.amplecode.staxwax.factory.XMLFactory;
@@ -58,7 +56,6 @@
import org.codehaus.stax2.XMLStreamReader2;
import org.hisp.dhis.common.ProcessState;
import org.hisp.dhis.external.location.LocationManager;
-import org.hisp.dhis.external.location.LocationManagerException;
import org.hisp.dhis.importexport.ImportParams;
import org.hisp.dhis.importexport.ImportService;
import org.hisp.dhis.importexport.dxf.converter.DXFConverter;
@@ -66,26 +63,23 @@
import org.hisp.dhis.system.util.StreamUtils;
/**
- *
* @author bobj
- * @version created 14-Feb-2010
*/
-public class DefaultXMLImportService implements ImportService
+public class DefaultXMLImportService
+ implements ImportService
{
-
public static final String DXF_ROOT = "dxf";
public static final String TRANSFORMERS_CONFIG = "transform/transforms.xml";
private final Log log = LogFactory.getLog( DefaultXMLImportService.class );
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
protected LocationManager locationManager;
- /**
- * Set the value of locationManager
- *
- * @param locationManager new value of locationManager
- */
public void setLocationManager( LocationManager locationManager )
{
this.locationManager = locationManager;
@@ -93,24 +87,13 @@
protected URIResolver dhisResolver;
- /**
- * Set the value of dhisResolver
- * This is used to resolve href uris in the xslt stylesheet
- *
- * @param dhisResolver new value of dhisResolver
- */
public void setDhisResolver( URIResolver dhisResolver )
{
this.dhisResolver = dhisResolver;
}
- DXFConverter converter;
+ private DXFConverter converter;
- /**
- * Set the value of converter
- *
- * @param converter
- */
public void setConverter( DXFConverter converter )
{
this.converter = converter;
@@ -122,63 +105,9 @@
importData( params, inputStream, new OutputHolderState() );
}
- /**
- * Open a stylesheet to transform xml with the provided root element
- *
- * @param root
- * @return open InputStream or null
- */
- private InputStream getStyleSheetForRoot( StartElement root )
- {
- InputStream result = null;
- QName rootName = root.getName();
-
- String localpart = rootName.getLocalPart();
- String namespaceURI = rootName.getNamespaceURI();
-
- // Sdmx hd hack - this is a special case 'cos the transform will be dependent on KeyFamily ns
- // Its fragile because the CrossSectionalData element is not obliged to declare the KeyFamily ns.
- // But all current implementations do.
- // TODO: handle this more elegantly and robustly
- if ( localpart.equals( "CrossSectionalData" ) )
- {
- log.info("SDMX cross sectional data file");
- // we might have it. Depends if the DataSet namespace is declared
- Iterator otherNamespaces = root.getNamespaces();
- while ( otherNamespaces.hasNext() )
- {
- Namespace ns = (Namespace) otherNamespaces.next();
- if ( ns.getNamespaceURI().contains( "KeyFamily" ) )
- {
- localpart = "DataSet";
- namespaceURI = ns.getNamespaceURI();
- log.info("KeyFamily = "+namespaceURI);
- }
- }
- }
-
- if (namespaceURI==null) {
- namespaceURI="";
- }
-
- try
- {
- // look up the stylesheet from transformers.xml
- InputStream transformers = locationManager.getInputStream( TRANSFORMERS_CONFIG );
- String xpath =
- "/transforms/transform[(@root='" + localpart + "') and (@ns='" + namespaceURI + "')]/xslt";
- String stylesheet = "transform/"+XPathFilter.findText(transformers , xpath );
- transformers.close();
-
- if (stylesheet != null) {
- result = locationManager.getInputStream( stylesheet );
- }
- } catch ( Exception ex )
- {
- log.info( ex );
- }
- return result;
- }
+ // -------------------------------------------------------------------------
+ // ImportService implementation
+ // -------------------------------------------------------------------------
@Override
public void importData( ImportParams params, InputStream inputStream, ProcessState state )
@@ -194,8 +123,9 @@
InputStream xmlInStream;
// Importing of data from xml source is a three phase process
- // Phase 1: Get the XML stream
- // this could potentially be from a zip, a gzip or uncompressed dsource
+ // Phase 1: Get the XML stream
+ // this could potentially be from a zip, a gzip or uncompressed
+ // dsource
BufferedInputStream bufin = new BufferedInputStream( inputStream );
if ( StreamUtils.isZip( bufin ) )
@@ -203,12 +133,14 @@
// TODO: need a smart zip archive analyzer
xmlInStream = new ZipInputStream( bufin );
StreamUtils.getNextZipEntry( (ZipInputStream) xmlInStream );
- } else
+ }
+ else
{
if ( StreamUtils.isGZip( bufin ) )
{
xmlInStream = new GZIPInputStream( bufin );
- } else
+ }
+ else
{
// assume uncompressed xml
xmlInStream = bufin;
@@ -216,12 +148,14 @@
}
// Phase 2: get a STaX eventreader for the stream
- // On the basis of QName of root element perform additional transformation(s)
+ // On the basis of QName of root element perform additional
+ // transformation(s)
XMLInputFactory2 factory = (XMLInputFactory2) XMLInputFactory.newInstance();
XMLStreamReader2 streamReader = (XMLStreamReader2) factory.createXMLStreamReader( xmlInStream );
XMLEventReader2 eventReader = (XMLEventReader2) factory.createXMLEventReader( streamReader );
- // look for the document root element but don't pluck it from the stream
+ // look for the document root element but don't pluck it from the
+ // stream
while ( !eventReader.peek().isStartElement() )
{
eventReader.nextEvent();
@@ -236,7 +170,8 @@
{
// native dxf stream - no transform required
dxfReader = XMLFactory.getXMLReader( streamReader );
- } else
+ }
+ else
{
InputStream sheetStream = getStyleSheetForRoot( root );
if ( sheetStream == null )
@@ -259,21 +194,88 @@
StAXResult result = new StAXResult( pipeinput );
tt.transform( source, result, dhisResolver );
log.info( "transform successful - importing dxf" );
-
+
// set dxfReader to output of pipe
dxfReader = new DefaultXMLEventReader( (XMLEventReader2) pipeoutput );
}
+
// Phase 3: pass through to dxf convertor
-
converter.read( dxfReader, params, state );
dxfReader.closeReader();
StreamUtils.closeInputStream( xmlInStream );
state.setMessage( "import_process_done" );
- } catch ( Exception ex )
+ }
+ catch ( Exception ex )
{
log.error( "XML import error: " + ex );
state.setMessage( "import_process_failed" ); // see log for details
}
}
+
+ // -------------------------------------------------------------------------
+ // Supportive methods
+ // -------------------------------------------------------------------------
+
+ /**
+ * Open a stylesheet to transform xml with the provided root element
+ *
+ * @param root
+ * @return open InputStream or null
+ */
+ private InputStream getStyleSheetForRoot( StartElement root )
+ {
+ InputStream result = null;
+ QName rootName = root.getName();
+
+ String localpart = rootName.getLocalPart();
+ String namespaceURI = rootName.getNamespaceURI();
+
+ // Sdmx hd hack - this is a special case 'cos the transform will be
+ // dependent on KeyFamily ns
+ // Its fragile because the CrossSectionalData element is not obliged to
+ // declare the KeyFamily ns.
+ // But all current implementations do.
+ // TODO: handle this more elegantly and robustly
+ if ( localpart.equals( "CrossSectionalData" ) )
+ {
+ log.info( "SDMX cross sectional data file" );
+ // we might have it. Depends if the DataSet namespace is declared
+ Iterator<?> otherNamespaces = root.getNamespaces();
+ while ( otherNamespaces.hasNext() )
+ {
+ Namespace ns = (Namespace) otherNamespaces.next();
+ if ( ns.getNamespaceURI().contains( "KeyFamily" ) )
+ {
+ localpart = "DataSet";
+ namespaceURI = ns.getNamespaceURI();
+ log.info( "KeyFamily = " + namespaceURI );
+ }
+ }
+ }
+
+ if ( namespaceURI == null )
+ {
+ namespaceURI = "";
+ }
+
+ try
+ {
+ // look up the stylesheet from transformers.xml
+ InputStream transformers = locationManager.getInputStream( TRANSFORMERS_CONFIG );
+ String xpath = "/transforms/transform[(@root='" + localpart + "') and (@ns='" + namespaceURI + "')]/xslt";
+ String stylesheet = "transform/" + XPathFilter.findText( transformers, xpath );
+ transformers.close();
+
+ if ( stylesheet != null )
+ {
+ result = locationManager.getInputStream( stylesheet );
+ }
+ }
+ catch ( Exception ex )
+ {
+ log.info( ex );
+ }
+ return result;
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/dxf/DXFImportServiceTest.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/dxf/DXFImportServiceTest.java 2010-02-20 03:06:21 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/dxf/DXFImportServiceTest.java 2010-02-22 15:25:35 +0000
@@ -27,18 +27,13 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import static junit.framework.Assert.assertEquals;
+
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import static junit.framework.Assert.assertEquals;
-
import java.io.InputStream;
import java.io.OutputStream;
-import java.nio.channels.FileChannel;
import org.hisp.dhis.DhisTest;
import org.hisp.dhis.datadictionary.DataDictionaryService;
=== modified file 'dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/location/DefaultLocationManager.java'
--- dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/location/DefaultLocationManager.java 2009-12-10 13:30:07 +0000
+++ dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/location/DefaultLocationManager.java 2010-02-22 15:25:35 +0000
@@ -51,7 +51,6 @@
private static final Log log = LogFactory.getLog( DefaultLocationManager.class );
private static final String LINUX_DEFAULT_DHIS2_HOME = "/opt/dhis2";
- //private static final String LINUX_OS_NAME = "Linux";
private String externalDir = null;
=== modified file 'dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/location/DefaultLocationManagerResolver.java'
--- dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/location/DefaultLocationManagerResolver.java 2010-02-19 18:38:02 +0000
+++ dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/location/DefaultLocationManagerResolver.java 2010-02-22 15:25:35 +0000
@@ -1,15 +1,5 @@
package org.hisp.dhis.external.location;
-
-import java.net.URI;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import javax.xml.transform.Source;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.stream.StreamSource;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
/*
* Copyright (c) 2004-2005, University of Oslo
* All rights reserved.
@@ -37,49 +27,63 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.net.URI;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.URIResolver;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
/**
- *
+ *
* @author bobj
* @version created 12-Feb-2010
*/
-public class DefaultLocationManagerResolver implements LocationManagerResolver {
-
- private static final Log log = LogFactory.getLog(DefaultLocationManagerResolver.class);
-
- protected LocationManager lmanager;
-
- @Override
- public LocationManager getLocationManager()
- {
- return lmanager;
- }
-
- @Override
+public class DefaultLocationManagerResolver
+ implements URIResolver
+{
+ private static final Log log = LogFactory.getLog( DefaultLocationManagerResolver.class );
+
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ private LocationManager locationManager;
+
public void setLocationManager( LocationManager lm )
{
- lmanager = lm;
+ locationManager = lm;
}
- protected String basedir;
+ // -------------------------------------------------------------------------
+ // URIResolver implementation
+ // -------------------------------------------------------------------------
- public Source resolve( String href, String base ) throws TransformerException
+ public Source resolve( String href, String base )
+ throws TransformerException
{
Source result = null;
+
try
{
- URI uri = new URI(href);
+ URI uri = new URI( href );
String scheme = uri.getScheme();
- if ((scheme == null) || (scheme.equals( "file"))) {
+
+ if ( ( scheme == null ) || ( scheme.equals( "file" ) ) )
+ {
// TODO: test for absolute path reference
- result = new StreamSource( lmanager.getInputStream( href ) );
+ result = new StreamSource( locationManager.getInputStream( href ) );
}
- } catch ( Exception ex )
+ }
+ catch ( Exception ex )
{
log.warn( "URI resolve error: " + ex );
- throw (new TransformerException("Failed to resolve URI: " + href));
+ throw (new TransformerException( "Failed to resolve URI: " + href ));
}
return result;
-
}
}