How can assign multi parameters to the args in spring AOP pointcut - spring-aop

I wrote pointcut like this for the target method aaa. I want to enroll whole parameters of target method to the advice method's parameters. Could you let me know how can I make it.
target method
fun aaa(
#RequestParam(value = "startDate")
#DateTimeFormat(iso = DateTimeFormat.ISO.DATE) startDate: LocalDate,
#RequestParam(value = "endDate")
#DateTimeFormat(iso = DateTimeFormat.ISO.DATE) endDate: LocalDate,
#ModelAttribute privateInfoRequestDTO: PrivateInfoRequestDTO,
request: HttpServletRequest
)
advice method's pointcut
#Before("#annotation(com.blah.blah...) && args(privateInfoRequestDTO, startDate, endDate, request)")

Try JoinPoint.getArgs, if you need a generic solution matching any numbers and types of parameters.
If you know the relative positions from left or right of the parameters you wish to bind using args(...), such as 1st parameter, 2nd-last parameter etc., of course it is more comfortable and type-safe to stick with args.
Please also read some documentation before asking questions on StackOverflow next time. Thanks.

Related

Create a method that convert a List<SObject> to a Map<SObjectField, SObject> with SObjectField as method parameter, any suggestions?

global with sharing class test1 {
global Map<SObjectField, SObject> ConvertMap(List<SObject> listToConvert){
List<SObject> listToConvert = new List<SObject>;
Map<SObjectField, SObject> mapTest = new Map<SObjectField, SObject>;
mapTest.putAll(listToConvert);
return mapTest;
}
I've written this code, but it doesn't respect the request 'cause I can't put SObjectField as method parameter since the Map won't recognize the variable.
Does anyone have suggestions on how to do it?
Thank you in advance.
Do you really need SobjectField as map keys? the special class? If you're fine with strings as keys then there's a builtin, getPopulatedFieldsAsMap()
If you absolutely need SobjectField (I don't even know if it's serializable and can be passed to integrations, LWC etc)... You'd have to loop and marry the results to something like
Schema.describeSObjects(new List<String>{'Account'})[0].fields.getMap()

Odoo - Cannot loop through model records

I want to call a method every time my module gets installed or updated. Inside that method I want to loop through model records, but I'm only getting different errors.
This documentation looks pretty straightforward: https://www.odoo.com/documentation/9.0/reference/orm.html
But it doesn't work for me. I'm getting this error:
ParseError: "'account.tax' object has no attribute '_ids'" while parsing
This is how I call the method:
<openerp>
<data>
<function model="account.tax" name="_my_method" />
</data>
</openerp>
I took this from the first answer here: https://www.odoo.com/forum/help-1/question/how-can-i-execute-a-sql-statement-on-module-update-and-installation-6131
My model:
class my_account_tax(models.Model):
_name = 'account.tax'
_inherit = 'account.tax'
def _my_method(self, cr, uid, ids=None, context=None):
self.do_operation()
def do_operation(self):
print self
for record in self:
print record
It is basically a copy-paste from the docs. I only added method parameters cr, uid,.. If I take them away (and just leave 'self'), the error is a little different:
ParseError: "_my_method() takes exactly 1 argument (3 given)"
But also does not tell much.
use new api
#api.multi #if you use the new api you don't have to list all parameter in the function
def _my_method(self):
but you can keep it like that and do a pool on your model than loop throw the result that you get don't use self
if you use the new api use : self.env['model_name'].search([domain])

Flink Scala API functions on generic parameters

It's a follow up question on Flink Scala API "not enough arguments".
I'd like to be able to pass Flink's DataSets around and do something with it, but the parameters to the dataset are generic.
Here's the problem I have now:
import org.apache.flink.api.scala.ExecutionEnvironment
import org.apache.flink.api.scala._
import scala.reflect.ClassTag
object TestFlink {
def main(args: Array[String]) {
val env = ExecutionEnvironment.getExecutionEnvironment
val text = env.fromElements(
"Who's there?",
"I think I hear them. Stand, ho! Who's there?")
val split = text.flatMap { _.toLowerCase.split("\\W+") filter { _.nonEmpty } }
id(split).print()
env.execute()
}
def id[K: ClassTag](ds: DataSet[K]): DataSet[K] = ds.map(r => r)
}
I have this error for ds.map(r => r):
Multiple markers at this line
- not enough arguments for method map: (implicit evidence$256: org.apache.flink.api.common.typeinfo.TypeInformation[K], implicit
evidence$257: scala.reflect.ClassTag[K])org.apache.flink.api.scala.DataSet[K]. Unspecified value parameters evidence$256, evidence$257.
- not enough arguments for method map: (implicit evidence$4: org.apache.flink.api.common.typeinfo.TypeInformation[K], implicit evidence
$5: scala.reflect.ClassTag[K])org.apache.flink.api.scala.DataSet[K]. Unspecified value parameters evidence$4, evidence$5.
- could not find implicit value for evidence parameter of type org.apache.flink.api.common.typeinfo.TypeInformation[K]
Of course, the id function here is just an example, and I'd like to be able to do something more complex with it.
How it can be solved?
you also need to have TypeInformation as a context bound on the K parameter, so:
def id[K: ClassTag: TypeInformation](ds: DataSet[K]): DataSet[K] = ds.map(r => r)
The reason is, that Flink analyses the types that you use in your program and creates a TypeInformation instance for each type you use. If you want to create generic operations then you need to make sure a TypeInformation of that type is available by adding a context bound. This way, the Scala compiler will make sure an instance is available at the call site of the generic function.

Set property on body using bean()

I'm trying to set a property called "articleId" on the exchange's body and I thought the most explicit way to do this would be to use bean(). However, I can't get it to work. When I have the following in my route:
.bean(body(Article.class), "setArticleId(${header.articleId})")
I get this error message:
Caused by: org.apache.camel.component.bean.MethodNotFoundException: Method with name: setArticleId(${header.articleId}) not found on bean: bodyAs[com.example.model.Article] of type: org.apache.camel.builder.ValueBuilder
My solution has been to use a processor() and a few lines of code in order to set the articleId property from the header value, but to me that seems like overkill.
I've been complaining on camel-users that there isn't a good way to do this. For now here is how I tackle it:
.setHeader("dummy").ognl("request.body.articleId = request.headers.articleId")
Which requires adding camel-ognl dependency.
UPDATE
Actually, there is also a language endpoint that can do this without the setHeader, but you have to say transform=false or else it replaces your body with the result:
.to("language:ognl:request.body.articleId = request.headers.articleId?transform=false") // remember ?transform=false
I think you need to spend some time to go through this page, if you don't know how to tell camel which method of the bean you want it invoke.
If you just want to set the exchange property, you can just use the DSL
setProperty("articleId", body());
to do this kind of work.

Change Value of ParamInfo after adding to DynamicParameters?

I'm calling a stored proc in a foreach loop and would like to change the value of one of the parameters on each iteration. Currently, there doesn't seem to be any way to access the parameters once they've been added to DynamicParameters although from reading the source, I can see that DynamicParameters does keep an internal Dictionary. Any reason why this isn't public or if there's another way to get at the ParamInfos to change values?
Update
What I have currently:
foreach ( var fooID in fooIDs )
{
var dynamicParameters = new DynamicParameters();
dynamicParameters.Add( ParameterNames.BarID, barID );
dynamicParameters.Add( ParameterNames.FooID, fooID);
connection.Execute( ProcNames.MyProc, dynamicParameters, commandType:CommandType.StoredProcedure );
}
Re-Add the parameter.
// Call Add() with new values.
dynamicParameters.Add(ParameterNames.BarID, differentBarID);
There is no real reason DynamicParameters is so secret about what it does, the ParamInfo class could be exposed and I would be happy to provide proper iteration/modification properties and/or methods. If you feel like you would like to pitch in, please submit a patch.
In the mean time you can simply implement IDynamicParameters which is the trivial interface we use to dispatch this to the underlying command, in your app. You can use DynamicParameters as a starting point.

Resources