def publishTable(table, catalog = None, workspace = None, overwrite=True, name=None, storename=None): if catalog is None: pass lyrname = xmlNameFixUp(name) # usually fixed up by now # check for table.name conflict in existing layer names where the table.name # is not the same as the user-chosen layer name, i.e. unintended overwrite resource = catalog.get_resource(table.name) if resource is not None and table.name != lyrname: raise Exception("PostGIS table name conflicts with " "existing GeoServer layer name: {0}\n" "You may need to rename GeoServer layer name." .format(table.name)) workspace = workspace if workspace is not None else catalog.get_default_workspace() connection = table.conn geodb = connection.geodb conname = "{0}_{1}".format(connection.name, table.schema) storename = xmlNameFixUp(storename or conname) if not xmlNameIsValid(storename): raise Exception("Database connection name is invalid XML and can " "not be auto-fixed: {0} -> {1}" .format(conname, storename)) if not geodb.user: raise Exception("GeoServer requires database connection's username " "to be defined") store = createPGFeatureStore(catalog, storename, workspace = workspace, overwrite = True, host = geodb.host, database = geodb.dbname, schema = table.schema, port = geodb.port, user = geodb.user, passwd = geodb.passwd) if store is not None: rscname = name if table.name != name else table.name grpswlyr = [] if overwrite: # See notes about possible issues in OGCatalog._publishExisting() flyr = catalog.get_layer(rscname) if flyr is not None: grpswlyr = groupsWithLayer(catalog, flyr) if grpswlyr: removeLayerFromGroups(catalog, flyr, grpswlyr) catalog.delete(flyr) frsc = store.get_resources(name=rscname) if frsc is not None: catalog.delete(frsc) epsg = table.srid if int(table.srid) != 0 else 4326 ftype = catalog.publish_featuretype(table.name, store, "EPSG:" + str(epsg)) # once table-based layer created, switch name to user-chosen if table.name != rscname: ftype.dirty["name"] = rscname ftype.dirty["title"] = rscname catalog.save(ftype) if overwrite and grpswlyr: ftype = catalog.get_resource(rscname) if ftype: addLayerToGroups(catalog, ftype, grpswlyr, workspace=workspace)
def publishTable(table, catalog=None, workspace=None, overwrite=True, name=None, storename=None): if catalog is None: pass lyrname = xmlNameFixUp(name) # usually fixed up by now # check for table.name conflict in existing layer names where the table.name # is not the same as the user-chosen layer name, i.e. unintended overwrite resource = catalog.get_resource(table.name) if resource is not None and table.name != lyrname: raise Exception("PostGIS table name conflicts with " "existing GeoServer layer name: {0}\n" "You may need to rename GeoServer layer name.".format( table.name)) workspace = workspace if workspace is not None else catalog.get_default_workspace( ) connection = table.conn geodb = connection.geodb conname = "{0}_{1}".format(connection.name, table.schema) storename = xmlNameFixUp(storename or conname) if not xmlNameIsValid(storename): raise Exception("Database connection name is invalid XML and can " "not be auto-fixed: {0} -> {1}".format( conname, storename)) if not geodb.user: raise Exception("GeoServer requires database connection's username " "to be defined") store = createPGFeatureStore(catalog, storename, workspace=workspace, overwrite=True, host=geodb.host, database=geodb.dbname, schema=table.schema, port=geodb.port, user=geodb.user, passwd=geodb.passwd) if store is not None: rscname = name if table.name != name else table.name grpswlyr = [] if overwrite: # See notes about possible issues in OGCatalog._publishExisting() flyr = catalog.get_layer(rscname) if flyr is not None: grpswlyr = groupsWithLayer(catalog, flyr) if grpswlyr: removeLayerFromGroups(catalog, flyr, grpswlyr) catalog.delete(flyr) frsc = store.get_resources(name=rscname) if frsc is not None: catalog.delete(frsc) epsg = table.srid if int(table.srid) != 0 else 4326 ftype = catalog.publish_featuretype(table.name, store, "EPSG:" + str(epsg)) # once table-based layer created, switch name to user-chosen if table.name != rscname: ftype.dirty["name"] = rscname ftype.dirty["title"] = rscname catalog.save(ftype) if overwrite and grpswlyr: ftype = catalog.get_resource(rscname) if ftype: addLayerToGroups(catalog, ftype, grpswlyr, workspace=workspace)