From 94ae08701bbd7585a0b7e5a92d1975965a503c03 Mon Sep 17 00:00:00 2001 From: Dennis Kao <ulysseskao@gmail.com> Date: Wed, 15 Jan 2014 11:28:52 +0800 Subject: [PATCH] Merge branch 'origin/2.1.x' --- xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2ShpJob.java | 498 ++++++++++++++++++++---------------------------------- 1 files changed, 184 insertions(+), 314 deletions(-) diff --git a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2ShpJob.java b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2ShpJob.java index 1feb7f8..a01d871 100644 --- a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2ShpJob.java +++ b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2ShpJob.java @@ -6,14 +6,15 @@ import java.io.FilenameFilter; import java.io.IOException; import java.math.BigDecimal; +import java.nio.BufferOverflowException; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.channels.FileChannel; +import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.sql.Types; -import java.sql.Connection; import java.util.Date; import org.apache.commons.collections.OrderedMap; @@ -21,8 +22,8 @@ import org.apache.commons.collections.map.LinkedMap; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.geotools.feature.IllegalAttributeException; import org.geotools.feature.SchemaException; +import org.opengis.feature.IllegalAttributeException; import org.quartz.JobDetail; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; @@ -55,49 +56,41 @@ /** * */ -public class OracleConvertDgn2ShpJob extends AbstractOracleDatabaseJob -{ +public class OracleConvertDgn2ShpJob extends AbstractOracleDatabaseJob { final static Log logger = LogFactory.getLog(OracleConvertDgn2ShpJob.class); private static final int FETCHSIZE = 30; private static final int COMMITSIZE = 20; - class Pair - { + class Pair { Object first; Object second; - public Pair(Object first, Object second) - { + public Pair(Object first, Object second) { this.first = first; this.second = second; } } - GeometryFactory _geomFactory = new GeometryFactory(); - - public Log getLogger() - { + public Log getLogger() { return logger; } - protected AbstractOracleJobContext prepareJobContext(String targetSchemaName, String filterPath) - { - return new OracleConvertShapefilesJobContext(filterPath); + protected AbstractOracleJobContext prepareJobContext(String targetSchemaName, String filterPath, + boolean profileMode, boolean useTransform) { + return new OracleConvertShapefilesJobContext(filterPath, profileMode, useTransform); } - protected void extractJobConfiguration(JobDetail jobDetail) throws JobExecutionException - { + protected void extractJobConfiguration(JobDetail jobDetail) throws JobExecutionException { super.extractJobConfiguration(jobDetail); } - public void execute(JobExecutionContext context) throws JobExecutionException - { + public void execute(JobExecutionContext context) throws JobExecutionException { // Every job has its own job detail JobDetail jobDetail = context.getJobDetail(); // The name is defined in the job definition - String jobName = jobDetail.getName(); + String jobName = jobDetail.getKey().getName(); String targetSchemaName = null; @@ -105,31 +98,31 @@ logger.info(jobName + " fired at " + new Date()); extractJobConfiguration(jobDetail); createSourceDataStore(); - if (getSourceDataStore() == null) - { + if (getSourceDataStore() == null) { throw new JobExecutionException("Cannot connect source oracle database."); } - try - { + try { logger.info("-- step:clearOutputDirectory --"); clearOutputDirectory(); boolean bFirst = isCopyConnectivityMode(); - if (checkConvertDB()) - { + if (checkConvertDB()) { logger.info("-- step:convertOracleDB --"); - for (String orgSchema : _orgSchema) - { - OracleConvertShapefilesJobContext jobContext = (OracleConvertShapefilesJobContext) prepareJobContext(targetSchemaName, _filterPath); + for (String orgSchema : _orgSchema) { + OracleConvertShapefilesJobContext jobContext = (OracleConvertShapefilesJobContext) + prepareJobContext(targetSchemaName, _filterPath, isProfileMode(), isTransformed()); jobContext.setSourceDataStore(getSourceDataStore()); jobContext.setDataPath(_dataPath); jobContext.setConvertElementIn(_convertElementIn); jobContext.setElementLogging(checkElementLogging()); jobContext.setExecutionContext(context); - if (bFirst) - { + fetchTPData(jobContext); + logger.info("TPC DIST:" + jobContext.getDistId() + ":" + + ((jobContext.getDistName() == null) ? "NULL" : jobContext.getDistName())); + + if (bFirst) { copyConnectivity(jobContext); bFirst = false; } @@ -142,59 +135,39 @@ } } - if (checkConvertFile()) - { + if (checkConvertFile()) { logger.info("-- step:convertIndexDesignFile --"); convertIndexDesignFile(context); logger.info("-- step:convertOtherDesignFile --"); convertOtherDesignFile(context); } - if (checkConvertElementIn()) - { + if (checkConvertElementIn()) { logger.info("-- step:convertFeatureDesignFile --"); convertFeatureDesignFile(context); } - if (checkCreateDummy()) - { + if (checkCreateDummy()) { logger.info("-- step:createDummyFeatureFile --"); createDummyFeatureFile(context); } disconnect(); - } catch (SQLException e) - { + } catch (SQLException e) { logger.warn(e.getMessage(), e); throw new JobExecutionException("Database error. " + e.getMessage(), e); - } catch (IOException ex) - { + } catch (IOException ex) { logger.warn(ex.getMessage(), ex); throw new JobExecutionException("IO error. " + ex.getMessage(), ex); } logger.warn(jobName + " end at " + new Date()); } - /** - * Connectivity�ƻs�@�Ӫ����A�b�d�߹q�y��V�ɥΨӤ��OMS��Ʈw���q���s����(Connectivity) - * - * @param jobContext job context - * @throws SQLException sql exception - */ - private void copyConnectivity(OracleConvertShapefilesJobContext jobContext) throws SQLException - { - Connection connection = jobContext.getOracleConnection(); - Statement stmt = connection.createStatement(); - stmt.execute(OracleConvertShapefilesJobContext.TRUNCATE_CONNECTIVITY_WEBCHECK); - stmt.execute(OracleConvertShapefilesJobContext.COPY_CONNECTIVITY_TO_WEBCHECK); - } - private void exetcuteConvert(OracleConvertShapefilesJobContext jobContext, - String querySchema, String dataPath) throws SQLException - { + String querySchema, String dataPath) throws SQLException { int order = 0; OrderedMap map = getBlobStorageList(jobContext.getOracleConnection(), querySchema, "SD$SPACENODES" - , null); + , null); logger.info("begin convert job:[" + map.size() + "]:testmode=" + _testMode); @@ -205,8 +178,7 @@ //jobContext.startTransaction(); jobContext.setCurrentSchema(querySchema); jobContext.getExecutionContext().put("ConvertDgn2ShpJobProgress", 0); - for (OrderedMapIterator it = map.orderedMapIterator(); it.hasNext();) - { + for (OrderedMapIterator it = map.orderedMapIterator(); it.hasNext();) { it.next(); Pair pair = (Pair) it.getValue(); @@ -217,14 +189,12 @@ order++; - if (_testMode) - { + if (_testMode) { if ((_testCount < 0) || (order >= _testCount)) break; } - if ((order % COMMITSIZE) == 0) - { + if ((order % COMMITSIZE) == 0) { // OracleConnection connection = jobContext.getOracleConnection(); // connection.commitTransaction(); jobContext.commitTransaction(); @@ -234,8 +204,7 @@ } int now = order % step; - if (now != current) - { + if (now != current) { current = now; jobContext.getExecutionContext().put("ConvertDgn2ShpJobProgress", current); @@ -251,8 +220,7 @@ } protected OrderedMap getBlobStorageList(Connection connection, String schemaSrc, String tableSrc, - OrderedMap orderedMap) throws SQLException - { + OrderedMap orderedMap) throws SQLException { if (orderedMap == null) orderedMap = new LinkedMap(99); String fetchStmtFmt = "SELECT SNID, SPACETABLE FROM \"%s\".\"%s\""; @@ -263,17 +231,14 @@ stmt.setFetchSize(FETCHSIZE); - try - { + try { rs = stmt.executeQuery(fetchStmt); int size = rs.getMetaData().getColumnCount(); - while (rs.next()) - { + while (rs.next()) { Object[] values = new Object[size]; - for (int i = 0; i < size; i++) - { + for (int i = 0; i < size; i++) { values[i] = rs.getObject(i + 1); } @@ -286,13 +251,11 @@ else pair.first = name; } - } catch (SQLException e) - { + } catch (SQLException e) { logger.error(e.toString(), e); logger.error("stmt=" + fetchStmt); throw e; - } finally - { + } finally { if (rs != null) rs.close(); stmt.close(); } @@ -301,8 +264,7 @@ } protected OrderedMap getRawFormatStorageList(OracleConnection connection, String schemaSrc, String tableSrc, - OrderedMap orderedMap) throws SQLException - { + OrderedMap orderedMap) throws SQLException { if (orderedMap == null) orderedMap = new LinkedMap(99); String fetchStmtFmt = "SELECT RNID, SPACETABLE FROM \"%s\".\"%s\""; @@ -314,12 +276,10 @@ ResultSet rs = stmt.executeQuery(fetchStmt); int size = rs.getMetaData().getColumnCount(); - while (rs.next()) - { + while (rs.next()) { Object[] values = new Object[size]; - for (int i = 0; i < size; i++) - { + for (int i = 0; i < size; i++) { values[i] = rs.getObject(i + 1); } @@ -340,8 +300,7 @@ } protected void queryIgsetElement(OracleConvertShapefilesJobContext jobContext, - String srcschema, String srctable) throws SQLException - { + String srcschema, String srctable) throws SQLException { Connection connection = jobContext.getOracleConnection(); String fetchSrcStmtFmt = "SELECT IGDSELM FROM \"%s\".\"%s\" ORDER BY ROWID"; PrintfFormat spf = new PrintfFormat(fetchSrcStmtFmt); @@ -352,27 +311,29 @@ ResultSet rsSrc = stmtSrc.executeQuery(fetchSrcStmt); int igdsMetaType = rsSrc.getMetaData().getColumnType(1); - while (rsSrc.next()) - { - byte[] raw; + while (rsSrc.next()) { + byte[] raw = null; - if (igdsMetaType == Types.BLOB) - { + if (igdsMetaType == Types.BLOB) { BLOB blob = (BLOB) rsSrc.getBlob(1); - raw = getBytesFromBLOB(blob); - blob.close(); - } else - { + try { + raw = getBytesFromBLOB(blob); + } catch (BufferOverflowException e) { + logger.warn("Wrong Element Structure-", e); + } finally { + // blob.close(); + } + } else { raw = rsSrc.getBytes(1); } - try - { - Element element = fetchBinaryElement(raw); - jobContext.putFeatureCollection(element); - } catch (Dgn7fileException e) - { + try { + if (raw != null) { + Element element = fetchBinaryElement(raw); + jobContext.putFeatureCollection(element); + } + } catch (Dgn7fileException e) { logger.warn("Dgn7Exception", e); } } @@ -382,8 +343,7 @@ } protected void queryRawElement(OracleConvertShapefilesJobContext jobContext, - String srcschema, String srctable) throws SQLException - { + String srcschema, String srctable) throws SQLException { Connection connection = jobContext.getOracleConnection(); String fetchDestStmtFmt = "SELECT ELEMENT FROM \"%s\".\"%s\" ORDER BY ROWID"; PrintfFormat spf = new PrintfFormat(fetchDestStmtFmt); @@ -394,8 +354,7 @@ ResultSet rsDest = stmtDest.executeQuery(fetchDestStmt); - while (rsDest.next()) - { + while (rsDest.next()) { ARRAY rawsValue = ((OracleResultSet) rsDest).getARRAY(1); long[] rawData = rawsValue.getLongArray(); byte[] comparessedValue; @@ -414,12 +373,10 @@ byte[] rawDest = ByteArrayCompressor.decompressByteArray(comparessedValue); - try - { + try { Element element = fetchBinaryElement(rawDest); jobContext.putFeatureCollection(element); - } catch (Dgn7fileException e) - { + } catch (Dgn7fileException e) { logger.warn("Dgn7Exception:" + e.getMessage(), e); } } @@ -429,8 +386,7 @@ } // Binary to Element - private Element fetchBinaryElement(byte[] raws) throws Dgn7fileException - { + private Element fetchBinaryElement(byte[] raws) throws Dgn7fileException { ByteBuffer buffer = ByteBuffer.wrap(raws); buffer.order(ByteOrder.LITTLE_ENDIAN); short signature = buffer.getShort(); @@ -448,35 +404,28 @@ handler = recordType.getElementHandler(); Element dgnElement = (Element) handler.read(buffer, signature, elementLength); - if (recordType.isComplexElement() && (elementLength < raws.length)) - { + if (recordType.isComplexElement() && (elementLength < raws.length)) { int offset = elementLength; - while (offset < (raws.length - 4)) - { + while (offset < (raws.length - 4)) { buffer.position(offset); signature = buffer.getShort(); type = (byte) ((signature >>> 8) & 0x007f); elementLength = (buffer.getShort() * 2) + 4; - if (raws.length < (offset + elementLength)) - { + if (raws.length < (offset + elementLength)) { System.out.println("Length not match:" + offset + ":" + buffer.position() + ":" + buffer.limit()); break; } recordType = ElementType.forID(type); handler = recordType.getElementHandler(); - if (handler != null) - { + if (handler != null) { Element subElement = (Element) handler.read(buffer, signature, elementLength); ((ComplexElement) dgnElement).add(subElement); offset += elementLength; - } else - { + } else { byte[] remain = new byte[buffer.remaining()]; System.arraycopy(raws, offset, remain, 0, buffer.remaining()); - for (int i = 0; i < remain.length; i++) - { - if (remain[i] != 0) - { + for (int i = 0; i < remain.length; i++) { + if (remain[i] != 0) { logger.info("fetch element has some error. index=" + (offset + i) + ":value=" + remain[i]); System.out.println("fetch element has some error. index=" + (offset + i) + ":value=" + remain[i]); } @@ -490,40 +439,34 @@ } /** - * �����ഫ�����ɪ��u�@ + * �����ഫ�����ɪ��u�@ * - * @param context �u�@�������� + * @param context �u�@�������� * @throws org.quartz.JobExecutionException * exception */ - private void convertIndexDesignFile(JobExecutionContext context) throws JobExecutionException - { + private void convertIndexDesignFile(JobExecutionContext context) throws JobExecutionException { File indexDir = new File(getDataPath(), "index"); - if (!indexDir.exists()) - { + if (!indexDir.exists()) { logger.info("index dir=" + indexDir + " not exist."); return; } - if (!indexDir.isDirectory()) - { + if (!indexDir.isDirectory()) { logger.info("index dir=" + indexDir + " is not a directory."); } - File[] dgnFiles = indexDir.listFiles(new FilenameFilter() - { - public boolean accept(File dir, String name) - { + File[] dgnFiles = indexDir.listFiles(new FilenameFilter() { + public boolean accept(File dir, String name) { return name.toLowerCase().endsWith(".dgn"); } }); - for (File dgnFile : dgnFiles) - { - IndexDgnConvertShpJobContext convertContext = new IndexDgnConvertShpJobContext(getDataPath()); + for (File dgnFile : dgnFiles) { + IndexDgnConvertShpJobContext convertContext = new IndexDgnConvertShpJobContext(getDataPath(), isProfileMode(), + isTransformed()); logger.debug("--- start dgnfile-" + dgnFile.toString() + " ---"); - try - { + try { convertContext.setExecutionContext(context); String dgnPaths[] = StringUtils.splitToArray(dgnFile.toString(), File.separator); convertContext.setFilename(dgnPaths[dgnPaths.length - 1]); @@ -540,28 +483,23 @@ convertContext.closeFeatureWriter(); System.gc(); System.runFinalization(); - } catch (FileNotFoundException e) - { + } catch (FileNotFoundException e) { convertContext.rollbackTransaction(); logger.warn(e.getMessage(), e); throw new JobExecutionException(e.getMessage(), e); - } catch (Dgn7fileException e) - { + } catch (Dgn7fileException e) { convertContext.rollbackTransaction(); logger.warn(e.getMessage(), e); throw new JobExecutionException(e.getMessage(), e); - } catch (IOException e) - { + } catch (IOException e) { convertContext.rollbackTransaction(); logger.warn(e.getMessage(), e); throw new JobExecutionException(e.getMessage(), e); - } catch (IllegalAttributeException e) - { + } catch (IllegalAttributeException e) { convertContext.rollbackTransaction(); logger.warn(e.getMessage(), e); throw new JobExecutionException(e.getMessage(), e); - } catch (SchemaException e) - { + } catch (SchemaException e) { convertContext.rollbackTransaction(); logger.warn(e.getMessage(), e); throw new JobExecutionException(e.getMessage(), e); @@ -570,98 +508,81 @@ } protected void scanIndexDgnElement(IndexDgnConvertShpJobContext convertContext) - throws Dgn7fileException, IOException, IllegalAttributeException, SchemaException - { + throws Dgn7fileException, IOException, IllegalAttributeException, SchemaException { Dgn7fileReader reader = convertContext.getReader(); int count = 0; Element lastComplex = null; - while (reader.hasNext()) - { - Dgn7fileReader.Record record = reader.nextElement(); - if (record.element() != null) - { + while (reader.hasNext()) { + Element.FileRecord record = reader.nextElement(); + if (record.element() != null) { Element element = (Element) record.element(); ElementType type = element.getElementType(); - if ((!type.isComplexElement()) && (!element.isComponentElement())) - { - if (lastComplex != null) - { - processIndexElement(lastComplex, convertContext); - lastComplex = null; - } + if ((!type.isComplexElement()) && (!element.isComponentElement())) { + if (lastComplex != null) { + processIndexElement(lastComplex, convertContext); + lastComplex = null; + } processIndexElement(element, convertContext); - } else if (element.isComponentElement()) - { - if (lastComplex != null) - { + } else if (element.isComponentElement()) { + if (lastComplex != null) { ((ComplexElement) lastComplex).add(element); } - } else if (type.isComplexElement()) - { - if (lastComplex != null) - { + } else if (type.isComplexElement()) { + if (lastComplex != null) { processIndexElement(lastComplex, convertContext); } - lastComplex = element; + lastComplex = element; } } count++; } - if (lastComplex != null) - { + if (lastComplex != null) { processIndexElement(lastComplex, convertContext); } logger.debug("ElementRecord Count=" + count); } - private void processIndexElement(Element element, IndexDgnConvertShpJobContext convertContext) throws IllegalAttributeException, SchemaException - { - if (element instanceof TextElement) - { + private void processIndexElement(Element element, IndexDgnConvertShpJobContext convertContext) throws IllegalAttributeException, SchemaException { + if (element instanceof TextElement) { convertContext.putFeatureCollection(element); } } /** - * �����ഫ��L�]�p���ɪ��u�@ + * �����ഫ��L�]�p���ɪ��u�@ * * @param context jobContext * @throws org.quartz.JobExecutionException * exception */ - private void convertOtherDesignFile(JobExecutionContext context) throws JobExecutionException - { + private void convertOtherDesignFile(JobExecutionContext context) throws JobExecutionException { File otherDir = new File(getDataPath(), "other"); - if (!otherDir.exists()) - { + if (!otherDir.exists()) { logger.info("other dir=" + otherDir + " not exist."); return; } - if (!otherDir.isDirectory()) - { + if (!otherDir.isDirectory()) { logger.info("other dir=" + otherDir + " is not a directory."); } - File[] dgnFiles = otherDir.listFiles(new FilenameFilter() - { - public boolean accept(File dir, String name) - { + File[] dgnFiles = otherDir.listFiles(new FilenameFilter() { + public boolean accept(File dir, String name) { return name.toLowerCase().endsWith(".dgn"); } }); - for (File dgnFile : dgnFiles) - { - GeneralDgnConvertShpJobContext convertContext = new GeneralDgnConvertShpJobContext(getDataPath()); + for (File dgnFile : dgnFiles) { + GeneralDgnConvertShpJobContext convertContext = new GeneralDgnConvertShpJobContext(getDataPath(), + isProfileMode(), + isTransformed()); logger.info("--- start dgnfile-" + dgnFile.toString() + " ---"); - try - { + try { convertContext.setExecutionContext(context); String dgnPaths[] = StringUtils.splitToArray(dgnFile.toString(), File.separator); convertContext.setFilename(dgnPaths[dgnPaths.length - 1]); @@ -678,28 +599,23 @@ convertContext.closeFeatureWriter(); System.gc(); System.runFinalization(); - } catch (FileNotFoundException e) - { + } catch (FileNotFoundException e) { convertContext.rollbackTransaction(); logger.warn(e.getMessage(), e); throw new JobExecutionException(e.getMessage(), e); - } catch (Dgn7fileException e) - { + } catch (Dgn7fileException e) { convertContext.rollbackTransaction(); logger.warn(e.getMessage(), e); throw new JobExecutionException(e.getMessage(), e); - } catch (IOException e) - { + } catch (IOException e) { convertContext.rollbackTransaction(); logger.warn(e.getMessage(), e); throw new JobExecutionException(e.getMessage(), e); - } catch (IllegalAttributeException e) - { + } catch (IllegalAttributeException e) { convertContext.rollbackTransaction(); logger.warn(e.getMessage(), e); throw new JobExecutionException(e.getMessage(), e); - } catch (SchemaException e) - { + } catch (SchemaException e) { convertContext.rollbackTransaction(); logger.warn(e.getMessage(), e); throw new JobExecutionException(e.getMessage(), e); @@ -708,48 +624,38 @@ } public void scanOtherDgnElement(GeneralDgnConvertShpJobContext convertContext) - throws Dgn7fileException, IOException, IllegalAttributeException, SchemaException - { + throws Dgn7fileException, IOException, IllegalAttributeException, SchemaException { Dgn7fileReader reader = convertContext.getReader(); int count = 0; Element lastComplex = null; - while (reader.hasNext()) - { - Dgn7fileReader.Record record = reader.nextElement(); - if (record.element() != null) - { + while (reader.hasNext()) { + Element.FileRecord record = reader.nextElement(); + if (record.element() != null) { Element element = (Element) record.element(); ElementType type = element.getElementType(); - if ((!type.isComplexElement()) && (!element.isComponentElement())) - { - if (lastComplex != null) - { - processOtherElement(lastComplex, convertContext); - lastComplex = null; - } + if ((!type.isComplexElement()) && (!element.isComponentElement())) { + if (lastComplex != null) { + processOtherElement(lastComplex, convertContext); + lastComplex = null; + } processOtherElement(element, convertContext); - } else if (element.isComponentElement()) - { - if (lastComplex != null) - { + } else if (element.isComponentElement()) { + if (lastComplex != null) { ((ComplexElement) lastComplex).add(element); } - } else if (type.isComplexElement()) - { - if (lastComplex != null) - { + } else if (type.isComplexElement()) { + if (lastComplex != null) { processOtherElement(lastComplex, convertContext); } - lastComplex = element; + lastComplex = element; } } count++; } - if (lastComplex != null) - { + if (lastComplex != null) { processOtherElement(lastComplex, convertContext); } @@ -757,57 +663,43 @@ } private void processOtherElement(Element element, GeneralDgnConvertShpJobContext convertContext) - throws IllegalAttributeException, SchemaException - { + throws IllegalAttributeException, SchemaException { convertContext.putFeatureCollection(element); } - private void clearOutputDirectory() - { + private void clearOutputDirectory() { File outDataPath = new File(getDataPath(), OracleConvertShapefilesJobContext.SHPOUTPATH); - if (outDataPath.exists() && outDataPath.isDirectory()) - { + if (outDataPath.exists() && outDataPath.isDirectory()) { deleteFilesInPath(outDataPath); } outDataPath = new File(getDataPath(), IndexDgnConvertShpJobContext.SHPOUTPATH); - if (outDataPath.exists() && outDataPath.isDirectory()) - { + if (outDataPath.exists() && outDataPath.isDirectory()) { deleteFilesInPath(outDataPath); } outDataPath = new File(getDataPath(), GeneralDgnConvertShpJobContext.SHPOUTPATH); - if (outDataPath.exists() && outDataPath.isDirectory()) - { + if (outDataPath.exists() && outDataPath.isDirectory()) { deleteFilesInPath(outDataPath); } } - private void deleteFilesInPath(File outDataPath) - { + private void deleteFilesInPath(File outDataPath) { deleteFilesInPath(outDataPath, true); } - private void deleteFilesInPath(File outDataPath, boolean removeSubDir) - { - if (!outDataPath.isDirectory()) - { + private void deleteFilesInPath(File outDataPath, boolean removeSubDir) { + if (!outDataPath.isDirectory()) { return; } File[] files = outDataPath.listFiles(); - for (File file : files) - { - if (file.isFile()) - { - if (!file.delete()) - { + for (File file : files) { + if (file.isFile()) { + if (!file.delete()) { logger.info("Cannot delete file-" + file.toString()); } - } else if (file.isDirectory()) - { + } else if (file.isDirectory()) { deleteFilesInPath(file, removeSubDir); - if (removeSubDir) - { - if (file.delete()) - { + if (removeSubDir) { + if (file.delete()) { logger.info("Cannot delete dir-" + file.toString()); } } @@ -815,34 +707,29 @@ } } - private void convertFeatureDesignFile(JobExecutionContext context) throws JobExecutionException - { + private void convertFeatureDesignFile(JobExecutionContext context) throws JobExecutionException { File elminDir = new File(getDataPath(), "elmin"); - if (!elminDir.exists()) - { + if (!elminDir.exists()) { logger.info("elmin dir=" + elminDir + " not exist."); return; } - if (!elminDir.isDirectory()) - { + if (!elminDir.isDirectory()) { logger.info("elmin dir=" + elminDir + " is not a directory."); } - File[] dgnFiles = elminDir.listFiles(new FilenameFilter() - { - public boolean accept(File dir, String name) - { + File[] dgnFiles = elminDir.listFiles(new FilenameFilter() { + public boolean accept(File dir, String name) { return name.toLowerCase().endsWith(".dgn"); } }); - for (File dgnFile : dgnFiles) - { - FeatureDgnConvertShpJobContext convertContext = new FeatureDgnConvertShpJobContext(getDataPath(), _filterPath); + for (File dgnFile : dgnFiles) { + FeatureDgnConvertShpJobContext convertContext = new FeatureDgnConvertShpJobContext(getDataPath(), _filterPath, + isProfileMode(), + isTransformed()); logger.info("--- start dgnfile-" + dgnFile.toString() + " ---"); - try - { + try { convertContext.setExecutionContext(context); String dgnPaths[] = StringUtils.splitToArray(dgnFile.toString(), File.separator); convertContext.setFilename(dgnPaths[dgnPaths.length - 1]); @@ -859,28 +746,23 @@ convertContext.closeFeatureWriter(); System.gc(); System.runFinalization(); - } catch (FileNotFoundException e) - { + } catch (FileNotFoundException e) { convertContext.rollbackTransaction(); logger.warn(e.getMessage(), e); throw new JobExecutionException(e.getMessage(), e); - } catch (Dgn7fileException e) - { + } catch (Dgn7fileException e) { convertContext.rollbackTransaction(); logger.warn(e.getMessage(), e); throw new JobExecutionException(e.getMessage(), e); - } catch (IOException e) - { + } catch (IOException e) { convertContext.rollbackTransaction(); logger.warn(e.getMessage(), e); throw new JobExecutionException(e.getMessage(), e); - } catch (IllegalAttributeException e) - { + } catch (IllegalAttributeException e) { convertContext.rollbackTransaction(); logger.warn(e.getMessage(), e); throw new JobExecutionException(e.getMessage(), e); - } catch (SchemaException e) - { + } catch (SchemaException e) { convertContext.rollbackTransaction(); logger.warn(e.getMessage(), e); throw new JobExecutionException(e.getMessage(), e); @@ -889,61 +771,49 @@ } public void scanFeatureDgnElement(FeatureDgnConvertShpJobContext convertContext) - throws Dgn7fileException, IOException, IllegalAttributeException, SchemaException - { + throws Dgn7fileException, IOException, IllegalAttributeException, SchemaException { Dgn7fileReader reader = convertContext.getReader(); int count = 0; Element lastComplex = null; - while (reader.hasNext()) - { - Dgn7fileReader.Record record = reader.nextElement(); - if (record.element() != null) - { + while (reader.hasNext()) { + Element.FileRecord record = reader.nextElement(); + if (record.element() != null) { Element element = (Element) record.element(); ElementType type = element.getElementType(); - if ((!type.isComplexElement()) && (!element.isComponentElement())) - { - if (lastComplex != null) - { - processFeatureElement(lastComplex, convertContext); - lastComplex = null; - } + if ((!type.isComplexElement()) && (!element.isComponentElement())) { + if (lastComplex != null) { + processFeatureElement(lastComplex, convertContext); + lastComplex = null; + } processFeatureElement(element, convertContext); - } else if (element.isComponentElement()) - { - if (lastComplex != null) - { + } else if (element.isComponentElement()) { + if (lastComplex != null) { ((ComplexElement) lastComplex).add(element); } - } else if (type.isComplexElement()) - { - if (lastComplex != null) - { + } else if (type.isComplexElement()) { + if (lastComplex != null) { processFeatureElement(lastComplex, convertContext); } - lastComplex = element; + lastComplex = element; } } count++; } - if (lastComplex != null) - { + if (lastComplex != null) { processFeatureElement(lastComplex, convertContext); } logger.debug("ElementRecord Count=" + count); } private void processFeatureElement(Element element, FeatureDgnConvertShpJobContext convertContext) - throws IllegalAttributeException, SchemaException - { + throws IllegalAttributeException, SchemaException { convertContext.putFeatureCollection(element); } - private void createDummyFeatureFile(JobExecutionContext context) throws JobExecutionException - { + private void createDummyFeatureFile(JobExecutionContext context) throws JobExecutionException { /* DummyFeatureConvertShpJobContext convertContext = new DummyFeatureConvertShpJobContext(getDataPath(), _filterPath); try { -- Gitblit v0.0.0-SNAPSHOT