Groovy date formatting problem - groovy

I am developing a groovy application and I am having problems when showing a Date field.
If I use the following notation:
<g:formatDate format="dd.MM.yyyy" date="${fieldValue(bean: incidentTicketSLAInstance, field: "erstellungsDatum")}"/>
I am getting the actual date instead of what is saved at the DB.
When I use this notation it works properly.
<g:formatDate format="dd.MM.yyyy" date="${incidentTicketSLAInstance?.erstellungsDatum}" />
am I doing something wrong here?
Are not both notations equivalent?
(BTW, the instance DO exists and erstellungsDatum is NOT null)
Thanks in advance,
Luis

the fieldValue call will return a String, not a Date object, which the makes formatDate not work correctly
You have to use the second notation (as you spotted)

Related

Groovy Pattern for matching a value in map

Hy guys, i'm working on a IDEA plugin and custom references. I have many references working, but i'm stuck with a difficult one.
I'd like to detect patterns in groovy such as this one :
result = run service: 'createAgreementItem', with: createAgreementItemInMap
In the above line, i'd like to get the createAgreementItem element to match.
run is defined in a groovy base script
package org.apache.ofbiz.service.engine
abstract class GroovyBaseScript extends Script {
//...
Map run(Map args) throws ExecutionServiceException {
return runService((String)args.get('service'), (Map)args.get('with', new HashMap()))
}
//...
The problem is, what i'm trying to get isn't technically a parameter, it's a value from a map with the key equals to service.
So this won't work :
GroovyPatterns.groovyLiteralExpression()
.methodCallParameter(0,
GroovyPatterns.psiMethod().withName("run")
.definedInClass("org.apache.ofbiz.service.engine.GroovyBaseScript"))
Do you have any ideas or any help ? Thanks in advance !
EDIT :
Actually, i'm looking for a doc or an example for any use of the org.jetbrains.plugins.groovy.lang.psi.patterns.GroovyPatterns
library.
I don't get it, maybe i'm not familiar enough with groovy though i used it a bit.
Any help welcome on this.
The problem is, what i'm trying to get isn't technically a parameter,
it's a value from a map with the key equals to "service"
If all you want to do is retrieve the service value from the Map then instead of args.get('with', new HashMap()) you could do args.with.service. If you wanted null safety, you could do args?.with?.service.

Groovy Server Pages (.gsp) test if variable is string

I have the following code in a Groovy Server Page:
How can I check if the value of IntegerNameValueListName is a string in general and not compare it only to one specific string ?
IntegerNameValueListName has the following value:
The usual Java instanceof operator should work, but bear in mind that GString values are not instanceof String so this may give you false negatives. Depending on exactly what you're trying to achieve a simple != '' or even a Groovy-truth test="${IntegerNameValueListName}" may be enough.

CRM 2011 ActivityPointer Earlybound type generated incorrectly?

I tried running this Query in CRM 2011:
var activity = (from a in crmService.ActivityPointerSet
where a.StateCode == ActivityPointerState.Open &&
a.ActivityTypeCode == "4201"
select a).First();
But I got this error:
Microsoft.Crm.Metadata.EntityMetadataNotFoundException: The entity with a name = '4201' was not found in the MetadataCache
After checking with the FilteredActivityPointer database view, I noticed that that column was defined as an int, not a string. I manually edited the generated class, changing the string to an int on the property, and it worked just fine.
Is there a bug in the early bound type generator (CrmSvcUtil.exe), or did I somehow create it wrong?
EDIT: After some more testing, it looks like the ActivityTypeCode is expecting the string "appointment". Don't know why it's showing differently in the database though...
I would imagine they have done this as ObjectTypeCodes are not guaranteed to be the same across different deployments (if you have more than one).
By using 'task', 'appointment' or 'email' (etc) there is no ambiguity.
I agree it seems a bit strange though!

When to use Value Formatter and when to use Value Resolver

I am still confused of when to use Value Formatter versus Value Resolver in automapper.
Say I have a nullable DateTime that I want to make into a specific date format(so the end result would be a string). Should I use Formatter in this case?
Thanks
I had the same question and chose Value Resolver based upon documentation from the author himself that Value Formatter is likely a design mistake:
https://github.com/AutoMapper/AutoMapper/wiki/Custom-value-formatters
However, that same author provided a response to what to use when here:
Why does AutoMapper have an IValueFormatter when it has a seemingly much more powerful ValueResolver?

Using constructor to load data in subsonic3?

I'm getting an error while trying to load an record through the constructor.
The constructor is:
public Document(Expression<Func<Document,bool>> expression);
and i try to load a single item in like this
var x = new Document(f=>f.publicationnumber=="xxx");
publicationnumber isn't a key but tried making an it an unique key and still no go..
Am i totally wrong regarding the use of the constructor? and can someone please tell me how to use that constructor?
The error i'm getting is:
Test method TestProject1.UnitTest1.ParseFileNameTwoProductSingleLanguage threw exception: System.NullReferenceException:
with the following stacktrace:
SubSonic.Query.SqlQuery.Where[T](Expression1` expression)
Load`[T]`(T item, Expression1expression)
db.Document..ctor(Expression``1 expression) in C:\#Projects\DocumentsSearchAndAdmin\DocumentsSearchAndAdmin\Generated\ActiveRecord.cs: line 5613
rest removed for simplicity
Regards
Dennis
Use == instead of =, i.e.:
...(f=>f.publicationnumber == "xxx");
I've just gotten the SubSonic source, and found out that it had to with the expression parser and my lack of knowledge thereof .. my right side of the expression was actually an item in an string array - and s[PUBNO] (PUBNO is a const) and it was looking for an column named s instead of publicationnumber, i don't know if this i a bug or not in the linq classes
none the less - i've managed to get it to work by creating a local variable containing the value of s[PUBNO] and using that instead...
//dennis

Resources