示例#1
0
def get_schema(context, request):
    """
        Webservice method to get a schema
    """
    schema = request.get('schema', '')
    if not schema:
        return helpers.error('You must give a schema name as parameter: /get_schema?schema=xxx.'
                             'The following schema names are available: %s' % ", ".join(all_schemas.keys()))
    if not schema in all_schemas:
        return helpers.error("The asked schema '%s' doesn't exist" % schema)
    jsonWriter = getUtility(IJSONWriter)
    return helpers.success("Got schema %s" % schema, schema=jsonWriter.write(all_schemas[schema]))
示例#2
0
def send_dmsfile(context, request):
    """
        Webservice method to send a dms file and create a plone object
    """
    if not getSecurityManager().checkPermission("imio.dms.ws: Use webservice", context):
        raise Unauthorized("You cannot access this webservice")

    jsonReader = getUtility(IJSONReader)
    json_data = request.get('json', '')
    if not json_data:
        return helpers.error("Missing json parameter in the post data of the request")
    input_params = jsonReader.read(json_data)
    try:
        validate(input_params, all_schemas['send_dmsfile_in'])
    except ValidationError, ve_obj:
        del input_params['data']
        msg = 'Validation error'
        if len(ve_obj.path):
            msg += " on '%s'" % ', '.join(ve_obj.path)
        return helpers.error("%s: %s" % (msg, ve_obj.message),
                             barcode=input_params['barcode'],
                             input=input_params)
示例#3
0
        validate(input_params, all_schemas['send_dmsfile_in'])
    except ValidationError, ve_obj:
        del input_params['data']
        msg = 'Validation error'
        if len(ve_obj.path):
            msg += " on '%s'" % ', '.join(ve_obj.path)
        return helpers.error("%s: %s" % (msg, ve_obj.message),
                             barcode=input_params['barcode'],
                             input=input_params)
    # check fields content
    # scan_date: YYYY-MM-DD
    try:
        scan_date = datetime.date(int(input_params['scan_date'][0:4]), int(input_params['scan_date'][5:7]),
                                  int(input_params['scan_date'][8:10]))
    except Exception, value_error:
        return helpers.error("Uncorrect scan_date value ('%s'): %s" % (input_params['scan_date'], value_error),
                             barcode=input_params['barcode'])
    # scan_hour: HH:mm:SS
    try:
        scan_time = datetime.time(int(input_params['scan_hour'][0:2]), int(input_params['scan_hour'][3:5]),
                                  int(input_params['scan_hour'][6:8]))
    except Exception, value_error:
        return helpers.error("Uncorrect scan_hour value ('%s'): %s" % (input_params['scan_hour'], value_error),
                             barcode=input_params['barcode'])
    # creator
    if api.user.get(username=input_params['creator']) is None:
        return helpers.error("The creator '%s' doesn't exist" % input_params['creator'],
                             barcode=input_params['barcode'])

    # needed to be encoded for base64 translation
    input_params['data'] = input_params['data'].encode('utf8')
#    writeTo(os.path.join(DATA_DIR, 'received.txt'), input_params['data'])