play.api.libs.json is not able to parse uuid string - scala

In scala play application, I am trying to parse uuid as a json response but getting error:
play.api.libs.json.Json.parse(s"""
{
"id" : "ac435876-fe73-4385-a9dd-af54ce2d7a7d"
}
""")
Error- play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[JsonParseException: Unrecognized token 'C': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false') at [Source: (String)"

Related

How to decode a string in scala to json payload?

I have a sample event which contains a string encoded value which has to decoded.What is the best way to decode and make it as json payload to load into kinesis.
"errors": [
{
"level": "error",
"message": "error: instance value (\"category\") not found in enum (possible values: [\"article\",\"section\",\"account\",\"subscription\",\"game\",\"tool\",\"stock\",\"gallery\",\"slideshow\",\"video\",\"error\",\"utility\",\"page\",\"funnel\",\"conversion\",\"(not provided)\"])\n level: \"error\"\n schema: {\"loadingURI\":\"#\",\"pointer\":\"/properties/type\"}\n instance: {\"pointer\":\"/type\"}\n domain: \"validation\"\n keyword: \"enum\"\n value: \"category\"\n enum: [\"article\",\"section\",\"account\",\"subscription\",\"game\",\"tool\",\"stock\",\"gallery\",\"slideshow\",\"video\",\"error\",\"utility\",\"page\",\"funnel\",\"conversion\",\"(not provided)\"]\n"
}
],
"failure_tstamp": "2021-02-22T18:30:06.276Z",
"line": "CwBkAAAADjE5Mi4xNDMuNTcuMjAyCgDIAAABd8sBcjwLANIAAAAFVVRGLTgLANwAAAASc3NjLTAuMTUuMC1raW5lc2lzCwEsAAAAbU1vemlsbGEvNS4wIChpUGhvbmU7IENQVSBpUGhvbmUgT1MgMTRfNCBsaWtlIE1hYyBPUyBYKSBBcHBsZVdlYktpdC82MDUuMS4xNSAoS0hUTUwsIGxpa2UgR2Vja28pIE1vYmlsZS8xNUUxNDgLATYAAAAhaHR0cHM6Ly9wdWJhZHMuZy5kb3VibGVjbGljay5uZXQvCwFAAAAAIy9jb20uc25vd3Bsb3dhbmFseXRpY3Muc25vd3Bsb3cvdHAyCwFUAAAKz3sic2NoZW1hIjoiaWdsdTpj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Gb3J3YXJkZWQtUHJvdG86IGh0dHBzAAAARFgtRm9yd2FyZGVkLVNlcnZlcjogdHJhZWZpay1leHRlcm5hbC1yZWQtdHJhZWZpay1oYS02Yzg2ODY5NDc5LWN4c3JzAAAAGVgtUmVhbC1JcDogMTkyLjE0My41Ny4yMDIAAAAbVGltZW91dC1BY2Nlc3M6IDxmdW5jdGlvbjE+AAAAEGFwcGxpY2F0aW9uL2pzb24LAWgAAAAQYXBwbGljYXRpb24vanNvbgsBkAAAABllbmRwb2ludC5zb3BoaS5uZXdzMjQuY29tCwGaAAAAJDY3NThlNDEzLWViMjQtNDJhOC05NmU5LTBiY2JhNGE0YmMxZQt6aQAAAEFpZ2x1OmNvbS5zbm93cGxvd2FuYWx5dGljcy5zbm93cGxvdy9Db2xsZWN0b3JQYXlsb2FkL3RocmlmdC8xLTAtMAA="
}
I was trying to read as below in code but its not
val sJson = JsonMethods.parse("{\n \"errors\": [\n {\n \"level\": \"error\",\n \"message\": \"error: instance value (\\\"category\\\") not found in enum (possible values: [\\\"article\\\",\\\"section\\\",\\\"account\\\",\\\"subscription\\\",\\\"game\\\",\\\"tool\\\",\\\"stock\\\",\\\"gallery\\\",\\\"slideshow\\\",\\\"video\\\",\\\"error\\\",\\\"utility\\\",\\\"page\\\",\\\"funnel\\\",\\\"conversion\\\",\\\"(not provided)\\\"])\\n level: \\\"error\\\"\\n schema: {\\\"loadingURI\\\":\\\"#\\\",\\\"pointer\\\":\\\"/properties/type\\\"}\\n instance: {\\\"pointer\\\":\\\"/type\\\"}\\n domain: \\\"validation\\\"\\n keyword: \\\"enum\\\"\\n value: \\\"category\\\"\\n enum: [\\\"article\\\",\\\"section\\\",\\\"account\\\",\\\"subscription\\\",\\\"game\\\",\\\"tool\\\",\\\"stock\\\",\\\"gallery\\\",\\\"slideshow\\\",\\\"video\\\",\\\"error\\\",\\\"utility\\\",\\\"page\\\",\\\"funnel\\\",\\\"conversion\\\",\\\"(not provided)\\\"]\\n\"\n }\n ],\n \"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MS4xNSAoS0hUTUwsIGxpa2UgR2Vja28pIE1vYmlsZS8xNUUxNDgAAAALQWNjZXB0OiAqLyoAAAAiQWNjZXB0LUVuY29kaW5nOiBnemlwLCBkZWZsYXRlLCBicgAAABZBY2NlcHQtTGFuZ3VhZ2U6IGVuLXVzAAAAKE9yaWdpbjogaHR0cHM6Ly9wdWJhZHMuZy5kb3VibGVjbGljay5uZXQAAAAqUmVmZXJlcjogaHR0cHM6Ly9wdWJhZHMuZy5kb3VibGVjbGljay5uZXQvAAAAH1gtRm9yd2FyZGVkLUZvcjogMTkyLjE0My41Ny4yMDIAAAArWC1Gb3J3YXJkZWQtSG9zdDogZW5kcG9pbnQuc29waGkubmV3czI0LmNvbQAAABVYLUZvcndhcmRlZC1Qb3J0OiA0NDMAAAAYWC1Gb3J3YXJkZWQtUHJvdG86IGh0dHBzAAAARFgtRm9yd2FyZGVkLVNlcnZlcjogdHJhZWZpay1leHRlcm5hbC1yZWQtdHJhZWZpay1oYS02Yzg2ODY5NDc5LWN4c3JzAAAAGVgtUmVhbC1JcDogMTkyLjE0My41Ny4yMDIAAAAbVGltZW91dC1BY2Nlc3M6IDxmdW5jdGlvbjE+AAAAEGFwcGxpY2F0aW9uL2pzb24LAWgAAAAQYXBwbGljYXRpb24vanNvbgsBkAAAABllbmRwb2ludC5zb3BoaS5uZXdzMjQuY29tCwGaAAAAJDY3NThlNDEzLWViMjQtNDJhOC05NmU5LTBiY2JhNGE0YmMxZQt6aQAAAEFpZ2x1OmNvbS5zbm93cGxvd2FuYWx5dGljcy5zbm93cGxvdy9Db2xsZWN0b3JQYXlsb2FkL3RocmlmdC8xLTAtMAA=\"\n}")
val payloadJsonValue = sJson \ "line"
val payvalue = JsonMethods.compact(JsonMethods.render(payloadJsonValue)).replace("\"", "")
val payloadBytes = base64Decoder.decode(payvalue)
print(payloadBytes.map(_.toChar).mkString)
Any way it can be decoded and converted as json payload

How to insert 'NULL' values for 'int' column tupes in Aurora PostgreSQL db using Python boto3 client

I have a CSV file (MS SQL server table export) and I would like to import it to Aurora Serverless PostgreSQL database table. I did a basic preprocessing of the CSV file to replace all of the NULL values in it (i.e. '') to "NULL". The file looks like that:
CSV file:
ID,DRAW_WORKS
10000002,NULL
10000005,NULL
10000004,FLEXRIG3
10000003,FLEXRIG3
The PostgreSQL table has the following schema:
CREATE TABLE T_RIG_ACTIVITY_STATUS_DATE (
ID varchar(20) NOT NULL,
DRAW_WORKS_RATING int NULL
)
The code I am using to read and insert the CSV file is the following:
import boto3
import csv
rds_client = boto3.client('rds-data')
...
def batch_execute_statement(sql, sql_parameter_sets, transaction_id=None):
parameters = {
'secretArn': db_credentials_secrets_store_arn,
'database': database_name,
'resourceArn': db_cluster_arn,
'sql': sql,
'parameterSets': sql_parameter_sets
}
if transaction_id is not None:
parameters['transactionId'] = transaction_id
response = rds_client.batch_execute_statement(**parameters)
return response
transaction = rds_client.begin_transaction(
secretArn=db_credentials_secrets_store_arn,
resourceArn=db_cluster_arn,
database=database_name)
sql = 'INSERT INTO T_RIG_ACTIVITY_STATUS_DATE VALUES (:ID, :DRAW_WORKS);'
parameter_set = []
with open('test.csv', 'r') as file:
reader = csv.DictReader(file, delimiter=',')
for row in reader:
entry = [
{'name': 'ID','value': {'stringValue': row['RIG_ID']}},
{'name': 'DRAW_WORKS', 'value': {'longValue': row['DRAW_WORKS']}}
]
parameter_set.append(entry)
response = batch_execute_statement(
sql, parameter_set, transaction['transactionId'])
However, there is an error that gets returned suggests that there is a type mismatch:
Invalid type for parameter parameterSets[0][5].value.longValue,
value: NULL, type: <class 'str'>, valid types: <class 'int'>"
Is there a way to configure Aurora to accept NULL values for types such as int?
Reading the boto3 documentation more carefully I found that we can use isNull value set to True in case a field is NULL. The bellow code snippet shows how to insert null value to the database:
...
entry = [
{'name': 'ID','value': {'stringValue': row['ID']}}
]
if row['DRAW_WORKS'] == 'NULL':
entry.append({'name': 'DRAW_WORKS', 'value': {'isNull': True}})
else:
entry.append({'name': 'DRAW_WORKS_RATING', 'value': {'longValue': int(row['DRAW_WORKS'])}})
parameter_set.append(entry)

Openapi3 and CSV response (for Dredd)

I test my Api with DREDD against it's specification (written in Openapi3 considering, painfull limitations of Support by Dredd considered). No I have one endpoint, which produces CSV-data if the Accept-header is set so.
'/my-endpoint':
summary: ...
description: ...
get:
# parameters:
# -
# in: header
# name: Accept
# description: "Response format: application/json or text/csv"
# example: "text/csv"
responses:
'200':
description: ...
content:
text/csv:
schema:
type: string
example:
summary: 'csv table'
value: 'cell1, cell2'
When I run the test with Dredd the test fails with
expected:
headers:
body:
[
{
"key": "summary",
"value": "csv table"
},
{
"key": "value",
"value": "cell1, cell2"
}
]
statusCode: 200
Clearly there is something misunderstood and Dredd expects still JSON. Also the API is not told to produce the CSV Version. If I commit in the Accept header in the code abvoe I get the very same result - the expecetd result above and as actual result the JSON version of the my-endpoint-data and also ad warning:
warn: API description parser warning in .../tmp/transformed.specs.yml: 'Parameter Object' 'name' in location 'header' should not be 'Accept', 'Content-Type' or 'Authorization'
I read here and here: Header parameters named Accept, Content-Type and Authorization are not allowed. To describe these headers, use the corresponding OpenAPI keywords - but what are they? According to this and this page it seems to be enough to specify a response of the given type but that is clearly not enough to tell Dredd to produce such a header.
You got an error because the value of the example key is meant to be a literal example value. So in your case it's treated as an object with the summary and value properties.
Change your definition to:
content:
text/csv:
schema:
type: string
example: 'cell1, cell2'
Or if you want to provide a summary/description for an example, use examples instead:
content:
text/csv:
schema:
type: string
examples:
csv table:
summary: A CSV table with 2 cells
value: 'cell1, cell2'

FactoryGirl gives wrong value on enum status field

I am trying to build a FactoryGirl factory for the Client.rb model:
Client.rb
enum status: [ :unregistered, :registered ]
has_many :quotation_requests
#Validations
validates :first_name,
presence: true,
length: {minimum: 2}
validates :last_name,
presence: true,
length: {minimum: 2}
validates :email, email: true
validates :status, presence: true
Factory:
FactoryGirl.define do
factory :client do
first_name "Peter"
last_name "Johnson"
sequence(:email) { |n| "peterjohnson#{n}#example.com" }
password "somepassword"
status "unregistered"
end
end
client_spec.rb
require 'rails_helper'
RSpec.describe Client, type: :model do
describe 'factory' do
it "has a valid factory" do
expect(FactoryGirl.build(:client).to be_valid
end
end
end
I get the following errorL
1) Client factory has a valid factory
Failure/Error: expect(FactoryGirl.build(:client, status: 'unregistered')).to be_valid
expected #<Client id: nil, email: "peterjohnson1#example.com", encrypted_password: "$2a$04$urndfdXNfKVqYB5t3kERZ.c.DUitIVXEZ6f19FNYZ2C...", first_name: "Peter", last_name: "Johnson", status: "0", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, created_at: nil, updated_at: nil> to be valid, but got errors: Status can't be blank
The error is that Status can't be blank.
I don't understand how this is possible as the factory is clearly assigning a value to the status attribute.
How can I get this factory to build a valid client object?
Rails 4.2
Using factory_girl 4.7.0
Using factory_girl_rails 4.7.0
This error was caused by the data type I used for the status attribute. I chose string instead of integer.
I solved the problem by running a new migration to change the data type of the status to integer.
class ChangeColumnTypeClientStatus < ActiveRecord::Migration
def change
change_column :clients, :status, :integer, default: 0
end
end
Now it works perfectly.
I think that you forgot the
let(:client) { FactoryGirl.create(:client) }
on your client_spec.rb
Where're you creating the client object?
Other issue may be that you assign on Factory:
status "unregistered"
instead of:
status :unregistered
as a symbol or due to is an enum maybe you should make
status 0 # :unregistered

coffeescript error: 'unexpected .' for console.log

Have no idea why I am getting this error but my code:
angular.module('authAppApp')
.factory 'AuthService', (Session) ->
# Service logic
# ...
# Public API here
{
login: (creds)->
res =
id: 1,
user:
id: 1,
role: "admin"
Session.create(res.id, res.user.id, res.user.role)
return
}
Error:
[stdin]:30:14: error: unexpected .
Session.create(res.id, res.user.id, res.user.role)
^
This also happens with console.log
Why?
It looks like your indentation is off:
res =
id: 1,
user:
id: 1,
role: "admin"
Session.create(res.id, res.user.id, res.user.role)
return
The indentation of Session should match the indentation of res =. Otherwise, the coffeescript compiler will parse it as a property of the object you are setting res to. In particular, it's probably expecting a : and a value after Session.