示例#1
0
 protected DataStore createSourceDataStore(FileSystemEvent fileEvent)
     throws IOException, ActionException {
   updateTask("Connecting to source DataStore");
   String fileType = getFileType(fileEvent);
   FeatureConfiguration sourceFeature = configuration.getSourceFeature();
   if (fileType.equals("xml")) {
     InputStream inputXML = null;
     try {
       inputXML = new FileInputStream(fileEvent.getSource());
       sourceFeature = FeatureConfiguration.fromXML(inputXML);
     } catch (Exception e) {
       throw new IOException("Unable to load input XML", e);
     } finally {
       IOUtils.closeQuietly(inputXML);
     }
   } else if (fileType.equals("shp")) {
     sourceFeature.getDataStore().put("url", DataUtilities.fileToURL(fileEvent.getSource()));
   }
   DataStore source = createDataStore(sourceFeature.getDataStore());
   // if no typeName is configured, takes the first one registered in store
   if (sourceFeature.getTypeName() == null) {
     sourceFeature.setTypeName(source.getTypeNames()[0]);
   }
   // if no CRS is configured, takes if from the feature
   if (sourceFeature.getCrs() == null) {
     sourceFeature.setCoordinateReferenceSystem(
         source.getSchema(sourceFeature.getTypeName()).getCoordinateReferenceSystem());
   }
   configuration.setSourceFeature(sourceFeature);
   return source;
 }
示例#2
0
 /**
  * Builds an attribute value to be written on output.
  *
  * @param sourceFeature source used to get values to write
  * @param attributeName name of the attribute in the output feature
  * @return
  */
 protected Object getAttributeValue(
     SimpleFeature sourceFeature, String attributeName, Map<String, String> mappings) {
   // gets mapping for renamed attributes
   if (configuration.getAttributeMappings().containsKey(attributeName)) {
     attributeName = configuration.getAttributeMappings().get(attributeName).toString();
   } else if (mappings.containsKey(attributeName)) {
     attributeName = mappings.get(attributeName);
   }
   return sourceFeature.getAttribute(attributeName);
 }
示例#3
0
 /**
  * Purge data on output feature, if requested.
  *
  * @param featureWriter
  * @throws IOException
  */
 protected void purgeData(FeatureStore<SimpleFeatureType, SimpleFeature> featureWriter)
     throws IOException {
   if (configuration.isPurgeData()) {
     updateTask("Purging existing data");
     featureWriter.removeFeatures(Filter.INCLUDE);
     updateTask("Data purged");
   }
 }
示例#4
0
 protected void failAction(String message, Throwable t) throws ActionException {
   if (LOGGER.isErrorEnabled()) {
     LOGGER.error(message);
     if (t != null) {
       LOGGER.error(getStackTrace(t));
     }
   }
   if (!configuration.isFailIgnored()) {
     final ActionException e = new ActionException(this, message, t);
     listenerForwarder.failed(e);
     throw e;
   }
 }
示例#5
0
  /**
   * Builds the output event, with information about the imported data.
   *
   * @param outputEvents
   * @param schema
   * @return
   * @throws FileNotFoundException
   * @throws ActionException
   */
  protected EventObject buildOutputEvent() throws FileNotFoundException, ActionException {
    updateTask("Building output event");
    FileOutputStream outStream = null;
    try {
      File outputDir = getTempDir();
      File outputFile = new File(outputDir.getAbsolutePath() + File.separator + "output.xml");

      //                    new File(outputDir, "output.xml");
      outStream = new FileOutputStream(outputFile);
      configuration.getOutputFeature().toXML(outStream);
      updateTask("Output event built");
      return new FileSystemEvent(outputFile, FileSystemEventType.FILE_ADDED);
    } catch (Exception e) {
      throw new ActionException(this, "Error writing output event");
    } finally {
      IOUtils.closeQuietly(outStream);
    }
  }
示例#6
0
 /**
  * Builds a Query Object for the source Feature.
  *
  * @param sourceStore
  * @return
  * @throws IOException
  */
 protected Query buildSourceQuery(DataStore sourceStore) throws IOException {
   Query query = new Query();
   query.setTypeName(configuration.getSourceFeature().getTypeName());
   query.setCoordinateSystem(configuration.getSourceFeature().getCoordinateReferenceSystem());
   return query;
 }
示例#7
0
 /**
  * Creates the destination DataStore, from the configuration connection parameters.
  *
  * @return
  * @throws IOException
  * @throws ActionException
  */
 protected DataStore createOutputDataStore() throws IOException, ActionException {
   updateTask("Connecting to output DataStore");
   return createDataStore(configuration.getOutputFeature().getDataStore());
 }