def PUT(self, name=None): try: logging.info("[LayMan][PUT] %s"% name) params = repr(web.input()) logging.info("[LayMan][PUT] Parameters: %s ... %s"%\ (str(params)[:500], str(params)[-500:])) global config if not self.auth.authorised: logging.error("[LayMan][PUT] Unauthorised") raise AuthError(401, "Authorisation failed. Are you logged-in?") code = 404 # 200, 404... message = "Call not supported: PUT "+name+" Please check the API doc or report a bug if appropriate." path = [d for d in name.split(os.path.sep) if d] # PUT "http://localhost:8080/layman/fileman/file.shp" if path[0] == "fileman": from fileman import FileMan fm = FileMan() fileName = path[-1] data = web.data() (code, message) = fm.putFile(self._getTargetFile( fileName), data) # PUT /layman/user/ # data: {screenName: "user", roles: [{roleTitle, roleName}, {roleTitle, roleName}]} elif path[0] == "user": from userprefs import UserPrefs up = UserPrefs(config) data = web.data() logging.debug(data) (code, message) = up.updateUser(userJsonStr=data) elif path[0] == "geoserver": from layed.gsconfig import GsConfig # /geoserver/style/style_name if path[1] == "style": #ws = None #if len(path) > 3: # ws = path[-2] gsc = GsConfig() # If PUT Style fails, gsconfig throws an exception try: gsc.putStyle(path[-1], web.data()) (code, message) = (200, "PUT Style OK") except Exception as e: code = 500 message = "PUT Style failed: " + str(e) # /layed/config/<layer>?usergroup=FireBrigade elif path[0] == "layed" and len(path) == 2: from layed import LayEd le = LayEd() layerName = path[1] inpt = web.input(usergroup=None) gsWorkspace = self.auth.getGSWorkspace(inpt.usergroup) data = web.data() data = json.loads(data) # string -> json usergroup = inpt.usergroup if (not usergroup) and ("usergroup" in data.keys()): logging.debug("[LayMan][PUT] Usergroup not provided in params, but given in data: %s"% data["usergroup"]) usergroup = data["usergroup"] fsUserDir = self.auth.getFSUserDir() fsGroupDir = self.auth.getFSGroupDir(usergroup) dbSchema = self.auth.getDBSchema(usergroup) gsWorkspace = self.auth.getGSWorkspace(usergroup) (code, message) = le.putLayerConfig(gsWorkspace, layerName, data, fsUserDir, fsGroupDir, dbSchema) success = self._setReturnCode(code) retval = self._jsonReply(code, message, success) return retval except LaymanError as le: return self._handleLaymanError(le) except Exception as e: return self._handleException(e)
def PUT(self, name=None): try: logging.info("[LayMan][PUT] %s"% name) params = repr(web.input()) logging.info("[LayMan][PUT] Parameters: %s ... %s"%\ (str(params)[:500], str(params)[-500:])) global config if not self.auth.authorised: logging.error("[LayMan][PUT] Unauthorised") raise AuthError(401, "Authorisation failed. Are you logged-in?") code = 404 # 200, 404... message = "Call not supported: PUT "+name+" Please check the API doc or report a bug if appropriate." path = [d for d in name.split(os.path.sep) if d] # PUT /files/<user>/file.shp" if path[0] == "files" and len(path) == 3: from fileman import FileMan fm = FileMan() # Everyone can PUT only his/her own files userName = self.auth.getUserName() if userName != path[1]: logging.error("[LayMan][PUT] %s is not authorized to put files of %s"% (userName, path[1])) raise AuthError(401, "Sorry, you are not authorized to update files of %s"% path[1]) fileName = path[-1] data = web.data() (code, message) = fm.putFile(self._getTargetFile( fileName), data) # PUT /data/<group>/{table|view|file}/<data>?fileName=Rivers.shp elif path[0] == "data" and len(path) == 4: from layed import LayEd le = LayEd() # Check authorization for the given group checkRole = self.auth.getRole(path[1]) if checkRole["roleName"] != path[1]: logging.error("[LayMan][PUT] Not authorized to PUT data for %s group"% path[1]) raise AuthError(401, "Sorry, you are not authorized to put data in %s group"% path[1]) # fileName must be given inpt = web.input() if not inpt.fileName: raise LaymanError(400, "'fileName' parameter must be given") # Note: currently all vectors are stored in database and all rasters are stored in filesystem. # If some vector is to be stored in the fs or some raster in the db, # LayEd.updateData() must be adjusted and receive path[2] as a parameter fsUserDir = self.auth.getFSUserDir() fsGroupDir = self.auth.getFSGroupDir(path[1]) dbSchema = self.auth.getDBSchema(path[1]) gsWorkspace = self.auth.getGSWorkspace(path[1]) (code, message) = le.updateData(path[3], gsWorkspace, fsUserDir, fsGroupDir, dbSchema, inpt.fileName) # PUT /layman/user/ # data: {screenName: "user", roles: [{roleTitle, roleName}, {roleTitle, roleName}]} elif path[0] == "user": from userprefs import UserPrefs up = UserPrefs(config) data = web.data() logging.debug(data) (code, message) = up.updateUser(userJsonStr=data) elif path[0] == "geoserver": from layed.gsconfig import GsConfig # /geoserver/style/style_name if path[1] == "style": #ws = None #if len(path) > 3: # ws = path[-2] gsc = GsConfig() # If PUT Style fails, gsconfig throws an exception try: gsc.putStyle(path[-1], web.data()) (code, message) = (200, "PUT Style OK") except Exception as e: code = 500 message = "PUT Style failed: " + str(e) # PUT /layers/<group>/<layer> # was /layed/config/<layer>?usergroup=FireBrigade elif path[0] == "layers" and len(path) == 3: from layed import LayEd le = LayEd() # Check authorization for the given group checkRole = self.auth.getRole(path[1]) if checkRole["roleName"] != path[1]: logging.error("[LayMan][PUT] Not authorized to PUT layer for %s group"% path[1]) raise AuthError(401, "Sorry, you are not authorized to put layer in %s group"% path[1]) data = web.data() data = json.loads(data) # string -> json fsUserDir = self.auth.getFSUserDir() fsGroupDir = self.auth.getFSGroupDir(path[1]) dbSchema = self.auth.getDBSchema(path[1]) gsWorkspace = self.auth.getGSWorkspace(path[1]) (code, message) = le.putLayerConfig(gsWorkspace, path[2], data, fsUserDir, fsGroupDir, dbSchema) success = self._setReturnCode(code) retval = self._jsonReply(code, message, success) return retval except LaymanError as le: return self._handleLaymanError(le) except Exception as e: return self._handleException(e)