public String getProject() {
return storeInfo.getName();
}
public void run() {
DataAccess da = null;
try {
NamespaceInfo namespace = catalog.getNamespaceByPrefix(storeInfo.getWorkspace().getName());
// prepare
CatalogBuilder builder = new CatalogBuilder(catalog);
da = storeInfo.getDataStore(null);
StyleGenerator styles = new StyleGenerator(catalog);
// cast necessary due to some classpath oddity/geoapi issue, the compiler
// complained about getNames() returning a List<Object>...
List<Name> names = da.getNames();
summary.setTotalLayers(names.size());
for (Name name : names) {
// start information
String layerName = name.getLocalPart();
summary.newLayer(layerName);
LayerInfo layer = null;
try {
builder.setStore(storeInfo);
FeatureTypeInfo featureType = builder.buildFeatureType(name);
builder.lookupSRS(featureType, true);
builder.setupBounds(featureType);
layer = builder.buildLayer(featureType);
layer.setDefaultStyle(styles.getStyle(featureType));
ImportStatus status = SUCCESS;
if(cancelled)
return;
// if we have a default
if (layer.getResource().getSRS() == null && layer.getResource().getNativeCRS() != null
&& defaultSRS != null) {
layer.getResource().setSRS(defaultSRS);
layer.getResource().setProjectionPolicy(ProjectionPolicy.REPROJECT_TO_DECLARED);
status = DEFAULTED_SRS;
}
// handler common error conditions
if (catalog.getFeatureTypeByName(namespace, layerName) != null) {
status = DUPLICATE;
} else if (layer.getResource().getSRS() == null && defaultSRS == null) {
status = MISSING_SRS;
} else if (layer.getResource().getLatLonBoundingBox() == null) {
status = MISSING_BBOX;
} else {
// try to save the layer
catalog.add(featureType);
try {
catalog.add(layer);
} catch(Exception e) {
// will be caught by the external try/catch, here we just try to undo
// the feature type saving (transactions, where are thou)
catalog.remove(featureType);
throw e;
}
}
summary.completeLayer(layerName, layer, status);
} catch (Exception e) {
e.printStackTrace();
summary.completeLayer(layerName, layer, e);
}
if(cancelled)
return;
}
summary.end();
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Import process failed", e);
summary.end(e);
} finally {
if(da != null)
da.dispose();
}
}