In DataWeave 1.0 I have a requirement to set the "Address" value to a text truncated based on the property "address.length". For example if address.length is > 25 then customer.addressLine1 needs to be truncated to the first 25 chars, otherwise set Address with value in "customer.addressLine1" as it is.
Code:
property file --> address.length=25
(ns2#Address: customer.addressLine1[0.."${address.length}" as :number-1] when ((((sizeOf (customer.addressLine1)) > ("${address.length}" as :number)))) otherwise customer.addressLine1)
Exception:
Root Exception stack trace:
com.mulesoft.weave.mule.exception.WeaveExecutionException: Exception while executing:
(ns2#Address: customer.addressLine1[0.."25" as :number-1] when ((((sizeOf (customer.addressLine1)) > ("25" as :number)))) otherwise customer.addressLine1
^
Type mismatch for 'Descendants Selector ..' operator
found :number
required :array.
(ns2#Address: customer.addressLine1[0 to "${address.length}" as :number - 1] when (sizeOf (customer.addressLine1)) > ("${address.length}" as :number) otherwise customer.addressLine1)
Try with the code above. The range selector is incorrect. It should be [0 to "${address.length}" as :number - 1]
The error says that you are using the descendant selector. The range selector should be used.
Related
I am getting a weird error while passing class and date to an ActiveJob with the Sidekiq adapter.
1] pry(main)> StripeTransactionsSyncJob.perform_later(Stripe::SyncCharges, nil, 3.days.ago.to_date)
ActiveJob::SerializationError: Unsupported argument type: Class
from /home/amit/.rvm/gems/ruby-2.5.8#immosite/gems/activejob-5.0.7.2/lib/active_job/arguments.rb:83:in `serialize_argument'
[2] pry(main)> StripeTransactionsSyncJob.perform_later('Stripe::SyncCharges', nil, 3.days.ago.to_date)
ActiveJob::SerializationError: Unsupported argument type: Date
from /home/amit/.rvm/gems/ruby-2.5.8#immosite/gems/activejob-5.0.7.2/lib/active_job/arguments.rb:83:in `serialize_argument'
As per the doc, ActiveJob should support both types of arguments out of the box. What is wrong here?
The guide you have referenced in your post refers to the v6.1.4 of Rails. See the version info on top-right corner on that page.
The guide for v5.0 doesn't explicitly specify about the arguments types supported. And looking at the source code (see below) for the version of Rails you are using i.e 5.0.7.2
def serialize_argument(argument)
case argument
when *TYPE_WHITELIST
argument
when GlobalID::Identification
convert_to_global_id_hash(argument)
when Array
argument.map { |arg| serialize_argument(arg) }
when ActiveSupport::HashWithIndifferentAccess
result = serialize_hash(argument)
result[WITH_INDIFFERENT_ACCESS_KEY] = serialize_argument(true)
result
when Hash
symbol_keys = argument.each_key.grep(Symbol).map(&:to_s)
result = serialize_hash(argument)
result[SYMBOL_KEYS_KEY] = symbol_keys
result
else
raise SerializationError.new("Unsupported argument type: #{argument.class.name}")
end
end
your passed argument types Class and Date are not supported and hence you are getting SerializationError.
Note: Whenever referring to the API-docs or Guide I would recommend to view them for the specific version of Rails you are using.
The Class/Date/DateTime/Time etc were not supported in Rails 5.0. So I need to use String form of data being passed to the Job.
For reference, here is the method(simplified) that does deserialization
def serialize_argument(argument)
case argument
when *[ NilClass, String, Integer, Float, BigDecimal, TrueClass, FalseClass ]
argument
when GlobalID::Identification
convert_to_global_id_hash(argument)
when Array
argument.map { |arg| serialize_argument(arg) }
when ActiveSupport::HashWithIndifferentAccess
result = serialize_hash(argument)
result[WITH_INDIFFERENT_ACCESS_KEY] = serialize_argument(true)
result
when Hash
symbol_keys = argument.each_key.grep(Symbol).map(&:to_s)
result = serialize_hash(argument)
result[SYMBOL_KEYS_KEY] = symbol_keys
result
else
raise SerializationError.new("Unsupported argument type: #{argument.class.name}")
end
end
I have a DataWeave message transformer, let's say:
%dw 2.0
import fail from dw::Runtime
output application/java
fun isValuePresent(value, message: String) = if ( value == null or isEmpty(value) ) fail(message) else value
---
{
brand: isValuePresent(payload.document[0].brand, p('import.error.missing.brand')),
...
I also have an error handler for this kind of errors.
Errors in Mule have their properties, like: description or detailedDescription.
Now normally, when I am catching other errors (like those from is true component) - everything is fine, error.description holds my error message, everything is fine.
But when an error produced by fail() is produced, I get a very big error description message:
""my error message here
Trace:
at fail (Unknown)
at isValuePresent (line: 13, column: 85)
at main (line: 23, column: 7)" evaluating expression: "%dw 2.0
import fail from dw::Runtime
output application/java
fun isValuePresent(value, message: String) = if ( value == null or isEmpty(value) ) fail(message) else value
---
{
brand: isValuePresent(payload.document[0].brand, p('import.error.missing.brand')),
...
...
etc, etc
It looks like the whole content of my dataweave script is added to the trace. And I just want to have:
my error message here
Trace:
at fail (Unknown)
at isValuePresent (line: 13, column: 85)
at main (line: 23, column: 7)" evaluating expression: "%dw 2.0
Is it possible to achieve this? Or I have I made some mistakes when designing this behaviour? Is there a way to fix this?
I don't think you can do anything about that. It is the way the error is reported with fail() and it is not customizable. Probably it depends on how DataWeave itself reports errors rather than fail() itself.
I'm new in Mulesoft, I'm following Quickstart guide. In Step 2 (https://developer.mulesoft.com/guides/quick-start/developing-your-first-mule-application), I need to receive variables from URI in this way:
[{'id' : attributes.uriParams.productId}]
But when I try my GET I have the following error in console:
**Message : "Cannot coerce Array ([{id: "2" as String {class: "java.lang.String"}}]) to Object 1| [{'id' : attributes.uriParams.productId}] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Trace: at main (line: 1, column: 1)" evaluating expression: "[{'id' : attributes.uriParams.productId}]". Error type : MULE:EXPRESSION Element : get:\products(productId):test_daniel-config/processors/1 # test6_db_connection:test_daniel.xml:133 (Select) Element XML : SELECT product.,CONCAT('["', (GROUP_CONCAT(variant.picture SEPARATOR '","')),'"]') AS pictures,CONCAT('[', GROUP_CONCAT('{"',variant.identifierType, '":"', variant.identifier, '"}'),']') AS identifiersFROM product INNER JOIN variant ON product.uuid = variant.productUUIDWHERE product.uuid = :id; #[[{'id' : attributes.uriParams.productId}]] *
Any Ideas? Thanks!
cannot coerce Array to object error pop's up when you are using an array where you were supposed to use an object.
in the exception above the uri-param should be treated as ab object i.e. enclosed in {} but its being treated as an array of objects [{}].
this is causing the error.
I try to do an Selenium-Acceptancetest 'Search Result List' with RSpec spec
And my Issue is
It should verify the count of a Button "Detail"
I would be happy to get help for start thinking as a coder; i am a manual tester stil.
My Problem now is:
Method Error
Failure/Error: expect(#driver.find_element(:xpath, "//a[contains(text(),'Details')]").to be > 4)
NoMethodError:
undefined method `to' for #<Selenium::WebDriver::Element:0x00000003fd4938>
Sources:
On my way to resolve the issue I tried to modify this and I found this
But its not working
thanksfully remaining!
my Test File:
# coding: utf-8
puts "this is #{File.basename(__FILE__)}"
extend RSpec::Expectations
extend RSpec::Matchers
describe 'SEL' do
before(:each) do
#driver = loadDriver()
end
after(:each) do
#driver.quit
end
it 'test_Page (SEL)' do
#get the page
...
#do input keyword 'Restaurant'
...
#click submit
...
#(Works!) temp Validation1: Is there a "Btn Details" in SearchResultList?
expect(#driver.find_element(:xpath, "//a[contains(text(),'Details')]").displayed?)
#(Works not!) Validation: Are there more than "5 Btns Detail"
expect(#driver.find_element(:xpath, "//a[contains(text(),'Details')]").to be > 5)
end
end
Update after first answer:
Given I use
expect(#driver.find_elements(:xpath, "//a[contains(text(),'Details')]")).to be > 0
it hits that error:
Failure/Error: expect(#driver.find_elements(:xpath, "//a[contains(text(),'Details')]")).to be > 0
expected: > 0
got: [#<Selenium::WebDriver::Element:0xa6219008 id="a2a2c83a-e52d-4464-81ec-4fce07ccc0b6">, #<Selenium::We...64378279">, #<Selenium::WebDriver::Element:0x..f90cc8d0e id="de990e21-eecf-48db-873b-76515dba7c3e">]
Given the error message:
undefined method `to' for #<Selenium::WebDriver::Element:0x00000003fd4938>
I suspect your issue is a missing bracket. Normal Rspec syntax is
expect(something).to eq(some value).
I would imagine you are missing the closing parenthesis
expect(#driver.find_element(:xpath, "//a[contains(text(),'Details')]").to be > 5)
and this should be something more like:
expect(#driver.find_element(:xpath, "//a[contains(text(),'Details')]")).to be > 5
Although I might guess you need to call a size function on the latter part as well as maybe use find elements. Maybe this will also be useful for you.
Below is the portion of the mapping in data mapper
dateTimeFormatter = new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
output.Date_of_Rate_Float__c = (isnull(input.Date_of_Rate_Float) ? null : dateTimeFormatter.format(input.Date_of_Rate_Float));
output.Loan_Create_Date__c = (isnull(input.loan_create_date) ? null : dateTimeFormatter.format(input.loan_create_date));
output.Estimated_Closing_Date__c = (isnull(input.estimated_closing_date) ? null : dateTimeFormatter.format(input.estimated_closing_date));
this throws the below exception
1. DateConverter does not support default String to 'Date' conversion. (org.apache.commons.beanutils.ConversionException)
org.apache.commons.beanutils.converters.DateTimeConverter:468 (null)
Root Exception stack trace:
org.apache.commons.beanutils.ConversionException: DateConverter does not support default String to 'Date' conversion.
at org.apache.commons.beanutils.converters.DateTimeConverter.toDate(DateTimeConverter.java:468)
at org.apache.commons.beanutils.converters.DateTimeConverter.convertToType(DateTimeConverter.java:343)
at org.apache.commons.beanutils.converters.AbstractConverter.convert(AbstractConverter.java:156)
at org.apache.commons.beanutils.ConvertUtilsBean.convert(ConvertUtilsBean.java:544)
at com.mulesoft.datamapper.transform.converter.ScalarValueConversion.convert(ScalarValueConversion.java:126)
at com.mulesoft.datamapper.transform.DataRecordContext.put(DataRecordContext.java:87)
at com.mulesoft.datamapper.transform.DataRecordContext.put(DataRecordContext.java:24)
at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeSetAccessor(ReflectiveAccessorOptimizer.java:308)
at org.mvel2.compiler.CompiledAccExpression.setValue(CompiledAccExpression.java:54)
at org.mvel2.ast.DeepAssignmentNode.getReducedValueAccelerated(DeepAssignmentNode.java:92)
at org.mvel2.MVELRuntime.execute(MVELRuntime.java:85)
at org.mvel2.compiler.CompiledExpression.getDirectValue(CompiledExpression.java:123)
at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:119)
at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:113)
at org.mvel2.MVEL.executeExpression(MVEL.java:942)
at org.mule.el.mvel.MVELExpressionExecutor.execute(MVELExpressionExecutor.java:50)
at com.mulesoft.datamapper.transform.DataMapperExpressionLanguage.evaluate(DataMapperExpressionLanguage.java:106)
at com.mulesoft.datamapper.transform.MelRecordTransform.transform(MelRecordTransform.java:56)
at org.jetel.component.Reformat.execute(Reformat.java:273)
at org.jetel.graph.Node.run(Node.java:465)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
********************************************************************************
I'am unable to find as what is causing this exception, I would like to seek help in resolving this issue.
Thank you in advance
It looks like a null value is being passed to the format method. To see how you can make it "null safe" you can look at the example at Format a Date, allowing null