Search in sources :

Example 21 with User

use of com.autentia.tnt.businessobject.User in project TNTConcept by autentia.

the class BillManager method getAllBitacoreBreakDowns.

public List<BillBreakDown> getAllBitacoreBreakDowns(Date start, Date end, Project project) {
    final List<BillBreakDown> desgloses = new ArrayList<BillBreakDown>();
    ActivityDAO activityDAO = ActivityDAO.getDefault();
    ActivitySearch actSearch = new ActivitySearch();
    actSearch.setBillable(new Boolean(true));
    actSearch.setStartStartDate(start);
    actSearch.setEndStartDate(end);
    List<Activity> actividadesTotal = new ArrayList<Activity>();
    Hashtable user_roles = new Hashtable();
    ProjectRoleDAO projectRoleDAO = ProjectRoleDAO.getDefault();
    ProjectRoleSearch prjRolSearch = new ProjectRoleSearch();
    prjRolSearch.setProject(project);
    List<ProjectRole> roles = projectRoleDAO.search(prjRolSearch, new SortCriteria("id", false));
    for (ProjectRole proyRole : roles) {
        actSearch.setRole(proyRole);
        List<Activity> actividades = activityDAO.search(actSearch, new SortCriteria("startDate", false));
        actividadesTotal.addAll(actividades);
    }
    for (Activity act : actividadesTotal) {
        String key = act.getRole().getId().toString() + act.getUser().getId().toString();
        if (!user_roles.containsKey(key)) {
            Hashtable value = new Hashtable();
            value.put("ROLE", act.getRole());
            value.put("USER", act.getUser());
            user_roles.put(key, value);
        }
    }
    Enumeration en = user_roles.keys();
    while (en.hasMoreElements()) {
        String key = (String) en.nextElement();
        Hashtable pair = (Hashtable) user_roles.get(key);
        actSearch.setBillable(new Boolean(true));
        actSearch.setStartStartDate(start);
        actSearch.setEndStartDate(end);
        ProjectRole pR = (ProjectRole) pair.get("ROLE");
        User u = (User) pair.get("USER");
        actSearch.setRole(pR);
        actSearch.setUser(u);
        List<Activity> actividadesUsuarioRol = activityDAO.search(actSearch, new SortCriteria("startDate", false));
        BillBreakDown brd = new BillBreakDown();
        brd.setConcept("Imputaciones (usuario - rol): " + u.getName() + " - " + pR.getName());
        brd.setAmount(pR.getCostPerHour());
        IvaApplicator.applyIvaToTaxableObject(start, brd);
        BigDecimal unitsTotal = new BigDecimal(0);
        for (Activity act : actividadesUsuarioRol) {
            BigDecimal unitsActual = new BigDecimal(act.getDuration());
            unitsActual = unitsActual.divide(new BigDecimal(60), 2, RoundingMode.HALF_UP);
            unitsTotal = unitsTotal.add(unitsActual);
        }
        brd.setUnits(unitsTotal);
        brd.setSelected(true);
        desgloses.add(brd);
    }
    ProjectCostDAO prjCostDAO = ProjectCostDAO.getDefault();
    ProjectCostSearch prjCostSearch = new ProjectCostSearch();
    prjCostSearch.setProject(project);
    List<ProjectCost> costes = prjCostDAO.search(prjCostSearch, new SortCriteria("id", false));
    for (ProjectCost proyCost : costes) {
        BillBreakDown brd = new BillBreakDown();
        brd.setConcept("Coste: " + proyCost.getName());
        brd.setUnits(new BigDecimal(1));
        brd.setAmount(proyCost.getCost());
        IvaApplicator.applyIvaToTaxableObject(start, brd);
        brd.setSelected(true);
        desgloses.add(brd);
    }
    return desgloses;
}
Also used : ProjectRoleDAO(com.autentia.tnt.dao.hibernate.ProjectRoleDAO) Enumeration(java.util.Enumeration) User(com.autentia.tnt.businessobject.User) ProjectCostDAO(com.autentia.tnt.dao.hibernate.ProjectCostDAO) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) ProjectCostSearch(com.autentia.tnt.dao.search.ProjectCostSearch) Activity(com.autentia.tnt.businessobject.Activity) ProjectRole(com.autentia.tnt.businessobject.ProjectRole) BigDecimal(java.math.BigDecimal) SortCriteria(com.autentia.tnt.dao.SortCriteria) ProjectRoleSearch(com.autentia.tnt.dao.search.ProjectRoleSearch) ActivitySearch(com.autentia.tnt.dao.search.ActivitySearch) ProjectCost(com.autentia.tnt.businessobject.ProjectCost) BillBreakDown(com.autentia.tnt.businessobject.BillBreakDown) ActivityDAO(com.autentia.tnt.dao.hibernate.ActivityDAO)

Example 22 with User

use of com.autentia.tnt.businessobject.User in project TNTConcept by autentia.

the class ReportGeneratorStandardImpl method buildGlobalHoursReportJrxml.

private byte[] buildGlobalHoursReportJrxml(String reportCategory) {
    String reportHeaderFileName = ReportUtil.REPORT_PREFIX + reportCategory + ReportUtil.PARTIAL_REPORT_PREFIX + ReportUtil.GLOBAL_HOUR_REPORT_HEADER_FILE;
    String reportInterFileName = ReportUtil.REPORT_PREFIX + reportCategory + ReportUtil.PARTIAL_REPORT_PREFIX + ReportUtil.GLOBAL_HOUR_REPORT_INTER_FILE;
    String reportFooterFileName = ReportUtil.REPORT_PREFIX + reportCategory + ReportUtil.PARTIAL_REPORT_PREFIX + ReportUtil.GLOBAL_HOUR_REPORT_FOOTER_FILE;
    Reader jrxmlHeader = null;
    Reader jrxmlFooter = null;
    Reader jrxmlInter = null;
    ByteArrayOutputStream report = new ByteArrayOutputStream();
    byte[] output = null;
    int posX = GLOBAL_HOUR_REPORT_INITIAL_X_POS;
    int colNum = GLOBAL_HOUR_REPORT_ALWAYS_PRESENT_COLS_NUM;
    int pageWidth;
    StringBuilder columnHeader = new StringBuilder();
    StringBuilder detail = new StringBuilder();
    StringBuilder summary = new StringBuilder();
    StringBuilder vars = new StringBuilder();
    GlobalHoursReportBean ghReportBean = new GlobalHoursReportBean();
    List<User> users = ghReportBean.getUsers();
    colNum += users.size();
    pageWidth = colNum * (GLOBAL_HOUR_REPORT_COLUMN_WIDTH + GLOBAL_HOUR_REPORT_SPACE_BETWEEN_COLS);
    summary.append("<summary>");
    summary.append("<band height='25'  isSplitAllowed='true' >");
    for (int l = 0; l < users.size(); l++) {
        User user = users.get(l);
        columnHeader.append("<staticText><reportElement x='").append(posX).append("' y='5' width='").append(GLOBAL_HOUR_REPORT_COLUMN_WIDTH).append("' height='").append(GLOBAL_HOUR_REPORT_HEADER_HEIGHT).append("' ").append("key='").append(GLOBAL_HOUR_REPORT_HEADER_FIELD_KEY + l).append("'/>");
        columnHeader.append("<box></box><textElement textAlignment='Center' verticalAlignment='Middle'>").append("<font pdfFontName='Helvetica-Bold' size='14' isBold='true'/></textElement>");
        columnHeader.append("<text><![CDATA[").append(user.getName()).append("]]></text></staticText>");
        columnHeader.append("<staticText><reportElement x='").append(posX).append("' y='74' width='").append(GLOBAL_HOUR_REPORT_SUBHEADER_WIDTH).append("' height='").append(GLOBAL_HOUR_REPORT_SUBHEADER_HEIGHT).append("' ").append("key='").append(GLOBAL_HOUR_REPORT_HOURS_FIELD_KEY + l).append("'/>");
        columnHeader.append("<box></box><textElement textAlignment='Center'>").append("<font /></textElement>");
        columnHeader.append("<text><![CDATA[Horas]]></text></staticText>");
        columnHeader.append("<staticText><reportElement x='").append(posX + GLOBAL_HOUR_REPORT_SUBHEADER_WIDTH + GLOBAL_HOUR_REPORT_HOURS_COL_SPACE).append("' y='74' width='").append(GLOBAL_HOUR_REPORT_SUBHEADER_WIDTH).append("' height='").append(GLOBAL_HOUR_REPORT_SUBHEADER_HEIGHT).append("'").append(" key='").append(GLOBAL_HOUR_REPORT_COST_FIELD_KEY + l).append("'/>");
        columnHeader.append("<box></box><textElement textAlignment='Center'>").append("<font /></textElement>");
        columnHeader.append("<text><![CDATA[Coste (€)]]></text></staticText>");
        detail.append("<subreport isUsingCache='true'>");
        detail.append("<reportElement x='").append(posX + GLOBAL_HOUR_REPORT_SUBREPORT_X_MARGIN).append("' y='8' ").append("width='").append(GLOBAL_HOUR_REPORT_SUBREPORT_WIDTH).append("' ").append("height='").append(GLOBAL_HOUR_REPORT_SUBREPORT_HEIGHT).append("' ").append("key='").append(GLOBAL_HOUR_REPORT_SUBREPORT_KEY + l).append("'/>");
        detail.append("<subreportParameter  name='eurosPerHour'>").append("<subreportParameterExpression><![CDATA[new java.lang.Double(").append(new Double(0)).append(")]]></subreportParameterExpression>").append("</subreportParameter>");
        detail.append("<subreportParameter  name='idUser'>").append("<subreportParameterExpression><![CDATA[new java.lang.Integer(").append(user.getId()).append(")]]></subreportParameterExpression>").append("</subreportParameter>");
        detail.append("<subreportParameter  name='idProject'>").append("<subreportParameterExpression><![CDATA[$F{project_id}]]></subreportParameterExpression>").append("</subreportParameter>");
        detail.append("<subreportParameter  name='startDate'>").append("<subreportParameterExpression><![CDATA[$P{Fecha inicio}]]></subreportParameterExpression>").append("</subreportParameter>");
        detail.append("<subreportParameter  name='endDate'>").append("<subreportParameterExpression><![CDATA[$P{Fecha fin}]]></subreportParameterExpression>").append("</subreportParameter>");
        detail.append("<subreportParameter  name='billable'>").append("<subreportParameterExpression><![CDATA[$V{billable}]]></subreportParameterExpression>").append("</subreportParameter>");
        detail.append("<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>");
        detail.append("<returnValue subreportVariable='Horas' toVariable='").append(GLOBAL_HOUR_REPORT_TOTAL_HOURS_KEY + l).append("' calculation='Sum'/>");
        detail.append("<returnValue subreportVariable='Coste' toVariable='").append(GLOBAL_HOUR_REPORT_TOTAL_COST_KEY + l).append("' calculation='Sum'/>");
        detail.append("<subreportExpression  class='java.lang.String'><![CDATA[$P{SUBREPORT_ACTIVITIES}]]></subreportExpression>");
        detail.append("</subreport>");
        summary.append("<textField isStretchWithOverflow='false' pattern='#,##0.00' isBlankWhenNull='true' evaluationTime='Now' hyperlinkType='None'  hyperlinkTarget='Self' >");
        summary.append("<reportElement x='").append(posX + GLOBAL_HOUR_REPORT_SUBREPORT_X_MARGIN).append("' y='5' width='").append(GLOBAL_HOUR_REPORT_SUBHEADER_WIDTH).append("' height='").append(GLOBAL_HOUR_REPORT_SUBHEADER_HEIGHT).append("' ").append("key='").append(GLOBAL_HOUR_REPORT_TOTAL_HOURS_KEY + l).append("'/><box></box>");
        summary.append("<textElement></textElement>");
        summary.append("<textFieldExpression   class='java.lang.Double'><![CDATA[$V{").append(GLOBAL_HOUR_REPORT_TOTAL_HOURS_VAR + l).append("}]]></textFieldExpression></textField>");
        summary.append("<textField isStretchWithOverflow='false' pattern='#,##0.00' isBlankWhenNull='true' evaluationTime='Now' hyperlinkType='None'  hyperlinkTarget='Self' >");
        summary.append("<reportElement x='").append(posX + GLOBAL_HOUR_REPORT_SUBREPORT_X_MARGIN + GLOBAL_HOUR_REPORT_SUBHEADER_WIDTH + GLOBAL_HOUR_REPORT_HOURS_COL_SPACE).append("' y='5' width='").append(GLOBAL_HOUR_REPORT_SUBHEADER_WIDTH).append("' height='").append(GLOBAL_HOUR_REPORT_SUBHEADER_HEIGHT).append("' ").append("key='").append(GLOBAL_HOUR_REPORT_TOTAL_COST_KEY + l).append("'/><box></box>");
        summary.append("<textElement ></textElement>");
        summary.append("<textFieldExpression   class='java.lang.Double'><![CDATA[$V{").append(GLOBAL_HOUR_REPORT_TOTAL_COST_VAR + l).append("}]]></textFieldExpression></textField>");
        vars.append("<variable name='").append(GLOBAL_HOUR_REPORT_TOTAL_HOURS_VAR + l).append("' class='java.lang.Double' resetType='Report' calculation='Sum'></variable>");
        vars.append("<variable name='").append(GLOBAL_HOUR_REPORT_TOTAL_COST_VAR + l).append("' class='java.lang.Double' resetType='Report' calculation='Sum'></variable>");
        posX = posX + GLOBAL_HOUR_REPORT_COLUMN_WIDTH + GLOBAL_HOUR_REPORT_SPACE_BETWEEN_COLS;
    }
    columnHeader.append("<staticText><reportElement y='5' x='").append(posX).append("' key='staticText-3' ");
    columnHeader.append("width='").append(GLOBAL_HOUR_REPORT_COLUMN_WIDTH).append("' ").append("height='").append(GLOBAL_HOUR_REPORT_HEADER_HEIGHT).append("' />");
    columnHeader.append("<box></box><textElement textAlignment='Center' verticalAlignment='Middle'><font pdfFontName='Helvetica-Bold' size='14' isBold='true'/></textElement>");
    columnHeader.append("<text><![CDATA[TOTAL ]]></text></staticText>");
    columnHeader.append("<staticText><reportElement x='").append(posX).append("' y='74' width='").append(GLOBAL_HOUR_REPORT_SUBHEADER_WIDTH).append("' height='").append(GLOBAL_HOUR_REPORT_SUBHEADER_HEIGHT).append("' ").append("key='").append(GLOBAL_HOUR_REPORT_HOURS_FIELD_KEY + users.size()).append("'/>");
    columnHeader.append("<box></box><textElement textAlignment='Center'>").append("<font /></textElement>");
    columnHeader.append("<text><![CDATA[Horas]]></text></staticText>");
    columnHeader.append("<staticText><reportElement x='").append(posX + GLOBAL_HOUR_REPORT_SUBHEADER_WIDTH + GLOBAL_HOUR_REPORT_HOURS_COL_SPACE).append("' y='74' width='").append(GLOBAL_HOUR_REPORT_SUBHEADER_WIDTH).append("' height='").append(GLOBAL_HOUR_REPORT_SUBHEADER_HEIGHT).append("'").append(" key='").append(GLOBAL_HOUR_REPORT_COST_FIELD_KEY + users.size()).append("'/>");
    columnHeader.append("<box></box><textElement textAlignment='Center'>").append("<font /></textElement>");
    columnHeader.append("<text><![CDATA[Coste (€)]]></text></staticText>");
    detail.append("<subreport isUsingCache='true'>");
    detail.append("<reportElement x='").append(posX + GLOBAL_HOUR_REPORT_SUBREPORT_X_MARGIN).append("' y='8' ").append("width='").append(GLOBAL_HOUR_REPORT_SUBREPORT_WIDTH).append("' ").append("height='").append(GLOBAL_HOUR_REPORT_SUBREPORT_HEIGHT).append("' ").append("key='").append(GLOBAL_HOUR_REPORT_SUBREPORT_KEY + users.size()).append("'/>");
    detail.append("<subreportParameter  name='idProject'>").append("<subreportParameterExpression><![CDATA[$F{project_id}]]></subreportParameterExpression>").append("</subreportParameter>");
    detail.append("<subreportParameter  name='billable'>").append("<subreportParameterExpression><![CDATA[$V{billable}]]></subreportParameterExpression>").append("</subreportParameter>");
    detail.append("<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>");
    detail.append("<returnValue subreportVariable='Horas' toVariable='").append(GLOBAL_HOUR_REPORT_TOTAL_HOURS_KEY + users.size()).append("' calculation='Sum'/>");
    detail.append("<returnValue subreportVariable='Coste' toVariable='").append(GLOBAL_HOUR_REPORT_TOTAL_COST_KEY + users.size()).append("' calculation='Sum'/>");
    detail.append("<subreportExpression  class='java.lang.String'><![CDATA[$P{SUBREPORT_TOTAL_COST}]]></subreportExpression>");
    detail.append("</subreport>");
    detail.append("<line direction='TopDown'>");
    detail.append("<reportElement x='2' y='1' height='0' key='line-1' width='").append((pageWidth - GLOBAL_HOUR_REPORT_SPACE_BETWEEN_COLS)).append("' />");
    detail.append("<graphicElement stretchType='NoStretch'/></line>");
    summary.append("<textField isStretchWithOverflow='false' pattern='#,##0.00' isBlankWhenNull='true' evaluationTime='Now' hyperlinkType='None'  hyperlinkTarget='Self' >");
    summary.append("<reportElement x='").append(posX + GLOBAL_HOUR_REPORT_SUBREPORT_X_MARGIN).append("' y='5' width='").append(GLOBAL_HOUR_REPORT_SUBHEADER_WIDTH).append("' height='").append(GLOBAL_HOUR_REPORT_SUBHEADER_HEIGHT).append("' ").append("key='").append(GLOBAL_HOUR_REPORT_TOTAL_HOURS_KEY + users.size()).append("'/><box></box>");
    summary.append("<textElement ></textElement>");
    summary.append("<textFieldExpression   class='java.lang.Double'><![CDATA[$V{").append(GLOBAL_HOUR_REPORT_TOTAL_HOURS_VAR + users.size()).append("}]]></textFieldExpression></textField>");
    summary.append("<textField isStretchWithOverflow='false' pattern='#,##0.00' isBlankWhenNull='true' evaluationTime='Now' hyperlinkType='None'  hyperlinkTarget='Self' >");
    summary.append("<reportElement x='").append(posX + GLOBAL_HOUR_REPORT_SUBREPORT_X_MARGIN + GLOBAL_HOUR_REPORT_SUBHEADER_WIDTH + GLOBAL_HOUR_REPORT_HOURS_COL_SPACE).append("' y='5' width='").append(GLOBAL_HOUR_REPORT_SUBHEADER_WIDTH).append("' height='").append(GLOBAL_HOUR_REPORT_SUBHEADER_HEIGHT).append("' ").append("key='").append(GLOBAL_HOUR_REPORT_TOTAL_COST_KEY + users.size()).append("'/><box></box>");
    summary.append("<textElement ></textElement>");
    summary.append("<textFieldExpression   class='java.lang.Double'><![CDATA[$V{").append(GLOBAL_HOUR_REPORT_TOTAL_COST_VAR + users.size()).append("}]]></textFieldExpression></textField>");
    summary.append("</band>");
    summary.append("</summary>");
    summary.append("</jasperReport>");
    vars.append("<variable name='").append(GLOBAL_HOUR_REPORT_TOTAL_HOURS_VAR + users.size()).append("' class='java.lang.Double' resetType='Report' calculation='Sum'></variable>");
    vars.append("<variable name='").append(GLOBAL_HOUR_REPORT_TOTAL_COST_VAR + users.size()).append("' class='java.lang.Double' resetType='Report' calculation='Sum'></variable>");
    try {
        pageWidth = (pageWidth < REPORT_A4_LANDSCAPE_MIN_WIDTH) ? REPORT_A4_LANDSCAPE_MIN_WIDTH : pageWidth;
        Hashtable<String, String> replacements = new Hashtable<String, String>();
        replacements.put("@PAGE_WIDTH@", String.valueOf(pageWidth));
        replacements.put("@COL_COUNT@", String.valueOf(colNum));
        replacements.put("@BG_WIDTH@", String.valueOf(pageWidth - 4));
        replacements.put("@DynamicVars@", vars.toString());
        reportHeaderFileName = getResourceAsURL(reportHeaderFileName).getFile();
        reportFooterFileName = getResourceAsURL(reportFooterFileName).getFile();
        reportInterFileName = getResourceAsURL(reportInterFileName).getFile();
        jrxmlHeader = new FileReader(reportHeaderFileName);
        jrxmlFooter = new FileReader(reportFooterFileName);
        jrxmlInter = new FileReader(reportInterFileName);
        // out = new PrintWriter(report);
        sendData(jrxmlHeader, report, replacements);
        sendText(columnHeader.toString(), report);
        sendData(jrxmlInter, report, replacements);
        sendText(detail.toString(), report);
        sendData(jrxmlFooter, report, replacements);
        sendText(summary.toString(), report);
        output = report.toByteArray();
    } catch (Exception t) {
        log.error("Error generando JRXML de parte de horas global", t);
    } finally {
        if (jrxmlHeader != null) {
            try {
                jrxmlHeader.close();
            } catch (IOException e) {
                log.error("Error cerrando fichero de cabecera", e);
            }
        }
        if (jrxmlFooter != null) {
            try {
                jrxmlFooter.close();
            } catch (IOException e) {
                log.error("Error cerrando fichero de pie", e);
            }
        }
        if (jrxmlInter != null) {
            try {
                jrxmlInter.close();
            } catch (IOException e) {
                log.error("Error cerrando fichero intermedio", e);
            }
        }
        if (report != null) {
            try {
                report.close();
            } catch (IOException e) {
                log.error("Error cerrando report", e);
            }
        }
    }
    return output;
}
Also used : User(com.autentia.tnt.businessobject.User) GlobalHoursReportBean(com.autentia.tnt.bean.activity.GlobalHoursReportBean) Hashtable(java.util.Hashtable) Reader(java.io.Reader) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) JRException(net.sf.jasperreports.engine.JRException) URISyntaxException(java.net.URISyntaxException) SQLException(java.sql.SQLException) IOException(java.io.IOException) ReportException(com.autentia.tnt.error.ReportException) FileReader(java.io.FileReader)

Example 23 with User

use of com.autentia.tnt.businessobject.User in project TNTConcept by autentia.

the class ContractExpirationNotificationBean_IT method should_not_send_email_when_contract_expires_in_3_months_and_1_day.

@Test
public void should_not_send_email_when_contract_expires_in_3_months_and_1_day() throws MessagingException {
    // create a user with a contract ending in 3 months and 1 day
    User user = SpringUtilsForTesting.createUser("contract-3m-1d");
    user.setEndContractDate(Date.from(LocalDate.now().plusMonths(3).plusDays(1).atStartOfDay(ZoneId.systemDefault()).toInstant()));
    UserDAO userDAO = (UserDAO) SpringUtils.getSpringBean("daoUser");
    userDAO.insert(user);
    ContractExpirationNotificationBean sut = new ContractExpirationNotificationBean(mailService);
    int userCount = sut.checkExpirationDate();
    assertThat(userCount, is(0));
}
Also used : User(com.autentia.tnt.businessobject.User) UserDAO(com.autentia.tnt.dao.hibernate.UserDAO) Test(org.junit.Test)

Example 24 with User

use of com.autentia.tnt.businessobject.User in project TNTConcept by autentia.

the class ContractExpirationNotificationBean_IT method should_send_email_when_contract_expires_in_3_months.

@Test
public void should_send_email_when_contract_expires_in_3_months() throws MessagingException {
    // create a user with a contract ending in 3 months from now
    User user = SpringUtilsForTesting.createUser("contract-3m");
    user.setEndContractDate(Date.from(LocalDate.now().plusMonths(3).atStartOfDay(ZoneId.systemDefault()).toInstant()));
    UserDAO userDAO = (UserDAO) SpringUtils.getSpringBean("daoUser");
    userDAO.insert(user);
    ContractExpirationNotificationBean sut = new ContractExpirationNotificationBean(mailService);
    int userCount = sut.checkExpirationDate();
    assertThat(userCount, is(1));
}
Also used : User(com.autentia.tnt.businessobject.User) UserDAO(com.autentia.tnt.dao.hibernate.UserDAO) Test(org.junit.Test)

Example 25 with User

use of com.autentia.tnt.businessobject.User in project TNTConcept by autentia.

the class ContractExpirationNotificationBean_IT method should_send_email_when_contract_expires_in_1_month.

@Test
public void should_send_email_when_contract_expires_in_1_month() throws MessagingException {
    // create a user with a contract ending in 1 month from now
    User user = SpringUtilsForTesting.createUser("contract-1m");
    user.setEndContractDate(Date.from(LocalDate.now().plusMonths(1).atStartOfDay(ZoneId.systemDefault()).toInstant()));
    UserDAO userDAO = (UserDAO) SpringUtils.getSpringBean("daoUser");
    userDAO.insert(user);
    ContractExpirationNotificationBean sut = new ContractExpirationNotificationBean(mailService);
    int userCount = sut.checkExpirationDate();
    assertThat(userCount, is(1));
}
Also used : User(com.autentia.tnt.businessobject.User) UserDAO(com.autentia.tnt.dao.hibernate.UserDAO) Test(org.junit.Test)

Aggregations

User (com.autentia.tnt.businessobject.User)70 Test (org.junit.Test)24 ArrayList (java.util.ArrayList)17 SortCriteria (com.autentia.tnt.dao.SortCriteria)15 SelectItem (javax.faces.model.SelectItem)11 UserDAO (com.autentia.tnt.dao.hibernate.UserDAO)10 Date (java.util.Date)9 Link (com.autentia.tnt.businessobject.Link)6 UserSearch (com.autentia.tnt.dao.search.UserSearch)5 Attributes (javax.naming.directory.Attributes)5 BasicAttributes (javax.naming.directory.BasicAttributes)5 Activity (com.autentia.tnt.businessobject.Activity)4 Attribute (javax.naming.directory.Attribute)4 BasicAttribute (javax.naming.directory.BasicAttribute)4 GlobalHourReport (com.autentia.tnt.businessobject.GlobalHourReport)3 GlobalHoursReportBean (com.autentia.tnt.bean.activity.GlobalHoursReportBean)2 Commissioning (com.autentia.tnt.businessobject.Commissioning)2 Objective (com.autentia.tnt.businessobject.Objective)2 Occupation (com.autentia.tnt.businessobject.Occupation)2 DataIntegrityException (com.autentia.tnt.dao.DataIntegrityException)2