@Override
protected String handleObjectPost(Object object) throws Exception {
String workspace = getAttribute( "workspace");
String dataStore = getAttribute( "datastore");
FeatureTypeInfo featureType = (FeatureTypeInfo) object;
//ensure the store matches up
if ( featureType.getStore() != null ) {
if ( !dataStore.equals( featureType.getStore().getName() ) ) {
throw new RestletException( "Expected datastore " + dataStore +
" but client specified " + featureType.getStore().getName(), Status.CLIENT_ERROR_FORBIDDEN );
}
}
else {
featureType.setStore( catalog.getDataStoreByName( workspace, dataStore ) );
}
//ensure workspace/namespace matches up
if ( featureType.getNamespace() != null ) {
if ( !workspace.equals( featureType.getNamespace().getPrefix() ) ) {
throw new RestletException( "Expected workspace " + workspace +
" but client specified " + featureType.getNamespace().getPrefix(), Status.CLIENT_ERROR_FORBIDDEN );
}
}
else {
featureType.setNamespace( catalog.getNamespaceByPrefix( workspace ) );
}
featureType.setEnabled(true);
CatalogBuilder cb = new CatalogBuilder(catalog);
cb.initFeatureType( featureType );
if ( featureType.getStore() == null ) {
//get from requests
DataStoreInfo ds = catalog.getDataStoreByName( workspace, dataStore );
featureType.setStore( ds );
}
NamespaceInfo ns = featureType.getNamespace();
if ( ns != null && !ns.getPrefix().equals( workspace ) ) {
//TODO: change this once the two can be different and we untie namespace
// from workspace
LOGGER.warning( "Namespace: " + ns.getPrefix() + " does not match workspace: " + workspace + ", overriding." );
ns = null;
}
if ( ns == null){
//infer from workspace
ns = catalog.getNamespaceByPrefix( workspace );
featureType.setNamespace( ns );
}
featureType.setEnabled(true);
catalog.add( featureType );
//create a layer for the feature type
catalog.add(new CatalogBuilder(catalog).buildLayer(featureType));
LOGGER.info( "POST feature type" + dataStore + "," + featureType.getName() );
return featureType.getName();
}