Jasper report Boolean - jasper-reports

I have a Boolean property in the domain object; so can be false, true or N/A if is null. I don't how could be the best option to represent it
<field name="isOSX" class="java.lang.Boolean">
<fieldDescription><![CDATA[device.isOSX]]></fieldDescription>
</field>

Usually you can use that boolean value to print a text o draw a image, using for example the properties:
**Text field expression** in Text Fields
or
**Print When expression** in some other report elements.

Related

Value list smart filter bar field of smart table not present despite being configured

I'm having trouble creating a value list for a field in the smart filter bar of a smart table.
I have an entity set ApplicationsOverviewItemSet with the following entity type definition in SEGW:
The smart table has to display this entity set's data. In its smart filter bar I'd like there to be a value list for the statute property. I defined another entity set called ApplicationStatuteSet with this SEGW entity type definition:
This entity set should be a list of possible statute values and their descriptions. I implemented its GET method in the extended data provider class, making sure to support all pagination query options ($top, $skip and $inlinecount). A basic GET query of the entity set now returns the following data in JSON format:
{
"d": {
"results": [
{
"__metadata": {
"id": "https://WEBWSD.<my company>:443/sap/opu/odata/sap/ZC_AD_SCHOLAR_SRV/ApplicationStatuteSet('007')",
"uri": "https://WEBWSD.<my company>:443/sap/opu/odata/sap/ZC_AD_SCHOLAR_SRV/ApplicationStatuteSet('007')",
"type": "ZC_AD_SCHOLAR_SRV.ApplicationStatute"
},
"STATUTE": "007",
"DESCR": "Visiting scholar"
},
{
"__metadata": {
"id": "https://WEBWSD.<my company>:443/sap/opu/odata/sap/ZC_AD_SCHOLAR_SRV/ApplicationStatuteSet('014')",
"uri": "https://WEBWSD.<my company>:443/sap/opu/odata/sap/ZC_AD_SCHOLAR_SRV/ApplicationStatuteSet('014')",
"type": "ZC_AD_SCHOLAR_SRV.ApplicationStatute"
},
"STATUTE": "014",
"DESCR": "International scholar"
}
]
}
}
I adjusted the extended model provider class to generate the following annotation in the service metadata document designating the ApplicationStatute entity as a value list provider for statute fields:
<Annotations Target="ZC_AD_SCHOLAR_SRV.ApplicationStatute" xmlns="http://docs.oasis-open.org/odata/ns/edm">
<Annotation Term="com.sap.vocabularies.Common.v1.ValueList">
<Record>
<PropertyValue Property="Label" String="Statutes"/>
<PropertyValue Property="CollectionPath" String="ApplicationStatuteSet"/>
<PropertyValue Property="SearchSupported" Bool="true"/>
<PropertyValue Property="Parameters">
<Collection>
<Record Type="com.sap.vocabularies.Common.v1.ValueListParameterInOut">
<PropertyValue Property="LocalDataProperty" PropertyPath="statute"/>
<PropertyValue Property="ValueListProperty" String="STATUTE"/>
</Record>
<Record Type="com.sap.vocabularies.Common.v1.ValueListParameterDisplayOnly">
<PropertyValue Property="ValueListProperty" String="DESCR"/>
</Record>
</Collection>
</PropertyValue>
</Record>
</Annotation>
</Annotations>
I regenerated and reactivated all runtime service artifacts.
In the UI5 front-end view declaration, I explicitly set the preventInitialDataFetchInValueHelpDialog
attribute of the statute field's ControlConfiguration element to false.
AFAIK, this is all one has to do to create a value list for a field.
Howver, if I press F4 in the Statute field of the smart filter bar I only get the following pop-up:
The select from list tab is missing and there is no value list to be seen …
An example of what I'd like to achieve is the value list that pops up when you press F4 in the Company Code field of the first SAPUI5 smart table sample app:
Does anyone know what I'm doing wrong or overlooking in creating the value list for the field?
Thanks in advance for all the help,
Joshua
We found the problem. The annotation target has to refer to the field in the entity to which you want to couple a value list. In my case it had to be "ApplicationsOverviewItem/statute".

Jasper - Pass GregorianCalendar from JSON datasource

In my report I have a field tripDate as java.util.GregorianCalendar:
<field name="tripDate" class="java.util.GregorianCalendar"/>
I need to create a JSON datasource and pass this field.
I tried with different kind of solutions such as:
...
"tripDate": "1601897363" // value as timestamp
...
or as Datetime object:
"tripDate": {
"date": "2020-08-12 10:10:10",
"timezone_type": 3,
"timezone": "Europe/Paris"
}
In both cases i get the error:
Unable to get value for JSON field "tripDate" of class java.util.GregorianCalendar
Field "tripDate" is of class java.util.GregorianCalendar and can not be converted.
There is a way to pass a java.util.GregorianCalendar field from JSON datasource?
JSON/JSONQL datasources work with java.util.Date and its subclasses.
So you should use one of those for your textField class.
Regarding parsing of the date/time JSON string, depending on how you feed the JSON to your report you could try:
with a dataAdapter XML file, you can set the date pattern either with Jaspersoft Studio or by hand:
<jsonDataAdapter ...>
...
<datePattern>yyyy-dd-MM hh:mm:ss</datePattern>
...
</jsonDataAdapter>
if you don't use a data adapter and rely only on the net.sf.jasperreports.json.source property, you also need to set this property in your JRXML:
<property name="net.sf.jasperreports.json.date.pattern" value="yyyy-dd-MM hh:mm:ss"/>
In the same manner you could set a pattern for parsing numbers.

How do I compare current date in jrxml file for jasper reports?

I want to compare date with current date but I am not getting how to represent current date in jrxml.
Code is something like this
<textFieldExpression class="java.lang.String">
<![CDATA[ $F{dueDate} > [new java.util.Date()] ? "some value" : "some other value" ]]>
</textFieldExpression>
Can you please tell me correct representation of this code?
Try using the before() method in the java.util.Date class when comparing the two dates. The following example worked for me:
<textFieldExpression class="java.lang.String"><![CDATA[($P{date1}).before(new java.util.Date()) ? "aaa" : "bbb"]]></textFieldExpression>
If you want to check the value you get for new Date(), you can put it in a textfield and print it somewhere in your report.

Dozer - map class field to a flat representation

I've been googling and trying different dozer configuration options but so far couldn't find a simple solution...
Problem is as follow:
class A {
String test;
B test2;
}
class B {
String test3;
String test4;
}
class C {
String test;
String test3;
String test4;
}
Now I would like to map all of the fields from A (including B) to a flat representation in C.
Is it possible to map it using just configuration? The problem is that I need to map B in many different classes and I don't want to write a mapping like this for each of them:
<mapping>
<class-a>A</class-a>
<class-b>C</class-b>
<field>
<a>test2.test3</a>
<b>test3</b>
</field>
<field>
<a>test2.test4</a>
<b>test4</b>
</field>
</mapping>
Would appreciate a solution for that :)
The trick is to use mapping IDs and "this". You need to define caseB only once and can reuse it.
<mapping map-id="caseB">
<class-a>B</class-a>
<class-b>C</class-b>
<field>
<a>test3</a>
<b>test3</b>
</field>
<field>
<a>test4</a>
<b>test4</b>
</field>
</mapping>
<mapping>
<class-a>A</class-a>
<class-b>C</class-b>
<field map-id="caseB">
<a>test2</a>
<b>this</b>
</field>
</mapping>
found on dozer faq :
Can I map one field into another field that is nested n layers deep in the destination object?
Yes. Dozer supports dot notation for nested fields. As with other dozer field mappings, these are bi-directional.
<field>
<a>someNestedObj.someOtherNestedObj.someField</a>
<b>someOtherField</b>
</field>
dozer FAQ

How to access a DTO attribute when DTO is inside a hashmap in DOZER mapping file

I have a UserDTO which has userID field. The HashMap has this DTO as value for key User_Details.
I want to use DOZER mapping to set the userID attribute from HashMap->User_Details->userId to attribute UserDisplayDTO->userId.
How can I do this in Dozer XML mapping?
<mapping map-id="testMapping">
<class-a>java.util.HashMap</class-a>
<class-b>com.common.dto.UserDisplayDTO</class-b>
<field>
<a key="User_Details">this</a>
<b>userId</b>
</field>
</mapping>
You have to define a custom converter for this. Atm, dozer xml mapping doesn't support a keybased hashmap lookup.
So for your case, you need something like
<field custom-converter="com.your.custom.converter.UserIdConverter">
<a>hashmapfield</a>
<b>userId</b>
</field>
In the UserIdConverter implementation, you would have to retrieve the value from the hashmap and return it (null checking etc. omitted for the sake of clarity):
#Override
public Long convertTo(HashMap map, Long userId) {
UserDTO dto = (UserDTO)map.get("User_Details");
return dto.getUserId();
}