@Override
protected String handleObjectPost(Object object) throws Exception {
String workspace = getAttribute( "workspace");
String wmsstore = getAttribute( "wmsstore");
WMSLayerInfo wml = (WMSLayerInfo) object;
//ensure the store matches up
WMSStoreInfo wms = catalog.getStoreByName( workspace, wmsstore, WMSStoreInfo.class);
if ( wml.getStore() != null ) {
if ( !wmsstore.equals( wml.getStore().getName() ) ) {
throw new RestletException( "Expected wms store " + wmsstore +
" but client specified " + wml.getStore().getName(), Status.CLIENT_ERROR_FORBIDDEN );
}
} else {
wml.setStore( wms );
}
//ensure workspace/namespace matches up
if ( wml.getNamespace() != null ) {
if ( !workspace.equals( wml.getNamespace().getPrefix() ) ) {
throw new RestletException( "Expected workspace " + workspace +
" but client specified " + wml.getNamespace().getPrefix(), Status.CLIENT_ERROR_FORBIDDEN );
}
} else {
wml.setNamespace( catalog.getNamespaceByPrefix( workspace ) );
}
wml.setEnabled(true);
NamespaceInfo ns = wml.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 );
wml.setNamespace( ns );
}
// fill in missing information
CatalogBuilder cb = new CatalogBuilder(catalog);
cb.setStore(wms);
cb.initWMSLayer( wml );
wml.setEnabled(true);
catalog.validate(wml, true).throwIfInvalid();
catalog.add( wml );
// create a layer for the feature type
catalog.add(new CatalogBuilder(catalog).buildLayer(wml));
LOGGER.info( "POST wms layer " + wmsstore + "," + wml.getName() );
return wml.getName();
}