# $SnapHashLicense:
#
# SnapLogic - Open source data services
#
# Copyright (C) 2008, SnapLogic, Inc. All rights reserved.
#
# See http://www.snaplogic.org for more information about
# the SnapLogic project.
#
# This program is free software, distributed under the terms of
# the GNU General Public License Version 2. See the LEGAL file
# at the top of the source tree.
#
# "SnapLogic" is a trademark of SnapLogic, Inc.
#
#
# $
from __future__ import with_statement
# $Id: pipeline_rh_front_end.py 2565 2008-04-20 22:18:03Z dhiraj $
"""
Request Handler wrappers around the Pipeline API.
These methods provide an API translation between the Pipeline API and
the internal API used by other modules.
This is for the benefit of the request handler (thus the RH prefix),
so that the request handler does not need to know all the internals
of how the various modules want to have message bodies and parameters interpreted.
"""
from snaplogic.server.http_request import HttpRequest
from snaplogic.server import RhResponse
from snaplogic.common.snap_exceptions import *
from snaplogic.server import pipeline_api
def rh_suggest_resource_values(http_req):
"""
Front-end to L{Pipeline.suggest_resource_values}.
"""
http_req.make_input_rp()
try:
resdef_dict = http_req.input.next()
except StopIteration:
return RhResponse(http_req.BAD_REQUEST, 'Pipeline ResDef missing')
(e_dict, new_dict) = pipeline_api.suggest_values(resdef_dict)
if e_dict is not None:
return RhResponse(http_req.BAD_REQUEST, e_dict)
return RhResponse(http_req.OK, new_dict)
def rh_validate(http_req):
"""
Front-end to L{Pipeline.validate}.
"""
http_req.make_input_rp()
try:
resdef_dict = http_req.input.next()
except StopIteration:
return RhResponse(http_req.BAD_REQUEST, 'Pipeline ResDef missing')
e_dict = pipeline_api.validate(resdef_dict)
if e_dict is not None:
return RhResponse(http_req.BAD_REQUEST, e_dict)
return RhResponse(http_req.OK, None)
|