String storeType = new DirectoryDataStoreFactory().getDisplayName();
Map<String, Serializable> params = new HashMap<String, Serializable>();
params.put(DirectoryDataStoreFactory.URLP.key, new File(directory).toURI().toURL().toString());
params.put(DirectoryDataStoreFactory.NAMESPACE.key, new URI(ns).toString());
DataStoreInfo si;
StoreInfo preExisting = getCatalog().getStoreByName(ws, project, StoreInfo.class);
boolean storeNew = false;
if(preExisting != null) {
if(!(preExisting instanceof DataStoreInfo)) {
error(new ParamResourceModel("storeExistsNotVector", this, project));
return;
}
si = (DataStoreInfo) preExisting;
if(!si.getType().equals(storeType) || !si.getConnectionParameters().equals(params)) {
error(new ParamResourceModel("storeExistsNotSame", this, project));
return;
}
// make sure it's enabled, we just verified the directory exists
si.setEnabled(true);
} else {
storeNew = true;
CatalogBuilder builder = new CatalogBuilder(getCatalog());
builder.setWorkspace(ws);
si = builder.buildDataStore(project);
si.getConnectionParameters().putAll(params);
si.setEnabled(true);
si.setType(storeType);
getCatalog().add(si);
}
// build and run the importer