I want to report the difference between endDate and startDate in assignment collection. I created a template in Jasper Studio.
@Document(collection = "assignment")
public class Assignment {
@Id
private String id;
private String bookId;
private String memberId;
private LocalDate startDate;
private LocalDate endDate;
private int duration;
}
This is my template:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.21.2.final using JasperReports Library version 6.21.2-8434a0bd7c3bbc37cbf916f2968d35e4b165821a -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Simple_Blue" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="9c135acb-7dac-47b2-905f-5df4527e1fdb">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="mongo-connection"/>
<queryString language="MongoDbQuery">
<![CDATA[{
"collectionName": "assignment",
"aggregate": [
{
"$project": {
"_id": 0,
"memberId": 1,
"bookId": 1,
"borrowingDuration": {
"$divide": [
{ "$subtract": ["$endDate", "$startDate"] },
{ "$literal": 86400000 }
]
}
}
}
]
}]]>
</queryString>
<field name="bookId" class="java.lang.String"/>
<field name="borrowingDuration" class="java.lang.Double"/>
<field name="memberId" class="java.lang.String"/>
<group name="Group1">
<groupExpression><![CDATA[$F{bookId}]]></groupExpression>
<groupHeader>
<band height="33">
<staticText>
<reportElement mode="Opaque" x="0" y="0" width="100" height="32" forecolor="#666666" backcolor="#E6E6E6" uuid="aea6a421-1033-450d-b8fa-98eb17a4de48"/>
<textElement>
<font size="12"/>
</textElement>
<text><![CDATA[bookId]]></text>
</staticText>
<textField>
<reportElement mode="Opaque" x="100" y="0" width="455" height="32" forecolor="#006699" backcolor="#E6E6E6" uuid="1e8f0089-2e61-4b8c-80a3-90ec8174a6b9"/>
<textElement>
<font size="24" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{bookId}]]></textFieldExpression>
</textField>
<line>
<reportElement x="-20" y="32" width="595" height="1" forecolor="#666666" uuid="e741bd4e-aeef-426c-a2b7-95b0a1f38120"/>
</line>
</band>
</groupHeader>
<groupFooter>
<band/>
</groupFooter>
</group>
<group name="Group2">
<groupExpression><![CDATA[$F{borrowingDuration}]]></groupExpression>
<groupHeader>
<band height="32">
<textField>
<reportElement x="100" y="0" width="455" height="32" forecolor="#006699" uuid="97fe286b-c429-4b32-b265-88af433b0abd"/>
<textElement>
<font size="22" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{borrowingDuration}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="0" y="0" width="100" height="20" forecolor="#666666" uuid="4c3b2255-049c-458f-b3e2-91f319e4e094"/>
<textElement>
<font size="12"/>
</textElement>
<text><![CDATA[borrowingDuration]]></text>
</staticText>
</band>
</groupHeader>
<groupFooter>
<band/>
</groupFooter>
</group>
<group name="Group3">
<groupExpression><![CDATA[$F{memberId}]]></groupExpression>
<groupHeader>
<band height="32">
<textField>
<reportElement x="100" y="0" width="455" height="32" forecolor="#006699" uuid="b6d561e6-9865-4ad9-8621-997525c14aef"/>
<textElement>
<font size="20" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{memberId}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="0" y="0" width="100" height="20" forecolor="#666666" uuid="b895387d-9a26-477d-8d2b-21458afc57f5"/>
<textElement>
<font size="12"/>
</textElement>
<text><![CDATA[memberId]]></text>
</staticText>
</band>
</groupHeader>
<groupFooter>
<band/>
</groupFooter>
</group>
<background>
<band/>
</background>
<title>
<band height="72">
<frame>
<reportElement mode="Opaque" x="-20" y="-20" width="595" height="92" backcolor="#006699" uuid="527313f3-f700-43bf-b184-56fcef4afbb1"/>
<staticText>
<reportElement x="20" y="20" width="234" height="43" forecolor="#FFFFFF" uuid="62f0909f-4201-49be-8bac-95d5d30e1185"/>
<textElement>
<font size="34" isBold="true"/>
</textElement>
<text><![CDATA[TITLE]]></text>
</staticText>
<staticText>
<reportElement x="395" y="43" width="180" height="20" forecolor="#FFFFFF" uuid="d5666361-4cd9-48e9-8907-7cd16e9fcf81"/>
<textElement textAlignment="Right">
<font size="14" isBold="false"/>
</textElement>
<text><![CDATA[Add a description here]]></text>
</staticText>
</frame>
</band>
</title>
<pageHeader>
<band height="13"/>
</pageHeader>
<columnHeader>
<band height="21">
<line>
<reportElement x="-20" y="20" width="595" height="1" forecolor="#666666" uuid="f2d0af12-fa73-4906-b8f3-fa10d0287892"/>
</line>
</band>
</columnHeader>
<detail>
<band height="54">
<line>
<reportElement positionType="FixRelativeToBottom" x="0" y="10" width="555" height="1" uuid="2374ca52-7dd1-4ede-8363-0934a6844a1e"/>
</line>
</band>
</detail>
<columnFooter>
<band/>
</columnFooter>
<pageFooter>
<band height="17">
<textField>
<reportElement mode="Opaque" x="0" y="4" width="515" height="13" backcolor="#E6E6E6" uuid="59261b44-683a-405d-8d05-3372747af075"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
</textField>
<textField evaluationTime="Report">
<reportElement mode="Opaque" x="515" y="4" width="40" height="13" backcolor="#E6E6E6" uuid="acf9584b-1a7c-4909-9a31-dbbd1646df61"/>
<textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
<textField pattern="EEEEE dd MMMMM yyyy">
<reportElement x="0" y="4" width="100" height="13" uuid="6b28d113-69a6-482b-ac16-617d15fcc1e3"/>
<textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
</textField>
</band>
</pageFooter>
<summary>
<band/>
</summary>
</jasperReport>
This is my controller:
@GetMapping("/report")
public byte[] generateReport() throws Exception {
try{
List<AssignmentDTO> assignmentDTOList= assignmentService.findAll();
Map<String, Object> params= new HashMap<String, Object>();
params.put("CompanyName", "Uzan");
params.put("AssignmentList", new JRBeanCollectionDataSource(assignmentDTOList));
JasperPrint assignReport= JasperFillManager.fillReport(JasperCompileManager.compileReport(ResourceUtils
.getFile("classpath:duration.jrxml").getAbsolutePath()), params, new JREmptyDataSource());
return new ResponseEntity<byte[]>(JasperExportManager.exportReportToPdf(assignReport), null, HttpStatus.OK).getBody();
}
catch (Exception e){
return new ResponseEntity<byte[]>(HttpStatus.INTERNAL_SERVER_ERROR).getBody();
}
}
and I get this error : Caused by: net.sf.jasperreports.engine.JRRuntimeException: No query executer factory registered for the "MongoDbQuery" language.
How can I fix this?