Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
4.0 kB
1
Indexable
Never
/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package com.daksa.cib.bank.web.table;

import com.daksa.cib.bank.infrastructure.web.DataTable;
import com.daksa.cib.core.domain.view.ForeignTransferRequestTableView;
import com.daksa.cib.core.repository.ForeignTransferRequestTableViewRepository;
import com.daksa.cib.util.persistence.TableParam;
import com.daksa.cib.util.persistence.TableResult;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.faces.view.ViewScoped;
import javax.inject.Inject;
import javax.inject.Named;
import javax.persistence.EntityManager;
import org.apache.commons.lang3.StringUtils;
import org.primefaces.model.SortOrder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author Muh Kanda
 */
@Named
@ViewScoped
public class ForeignTransferRequestNewTable extends DataTable<ForeignTransferRequestTableView> {
    
    private static final long serialVersionUID = 1L;
    private static final Logger LOG = LoggerFactory.getLogger(ForeignTransferRequestNewTable.class);

    @Inject
    private EntityManager entityManager;
    @Inject
    private ForeignTransferRequestTableViewRepository foreignTransferRequestTableViewRepository;
    
    private Date startDate;
    private Date endDate;
    private static final String SDF_PATTERN = "yyyy-MM-dd HH:mm:ss";
    
    public ForeignTransferRequestNewTable() {
        super(ForeignTransferRequestTableView.class);
    }
    
    @Override
    protected EntityManager getEntityManager() {
        return entityManager;
    }
    
    @Override
    public ForeignTransferRequestTableView getRowData(String rowKey) {
        return foreignTransferRequestTableViewRepository.find(rowKey);
    }
    
    @Override
    public String getRowKey(ForeignTransferRequestTableView object) {
            return object.getId();
    }
    
    @Override
    public List<ForeignTransferRequestTableView> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) {
        TableParam.SortOrder sortOrderTable;
        sortOrderTable = TableParam.SortOrder.DESCENDING;
        if (startDate != null && endDate != null) {
            filters.put("startDate", new SimpleDateFormat(SDF_PATTERN).format(startDate));
            filters.put("endDate", new SimpleDateFormat(SDF_PATTERN).format(endDate));
        }
        if (StringUtils.isEmpty(sortField)) {
            sortField = "createTimestamp";
            sortOrderTable = TableParam.SortOrder.DESCENDING;
        } else {
            if (sortOrder != null) {
                if (sortOrder == SortOrder.ASCENDING) {
                    sortOrderTable = TableParam.SortOrder.ASCENDING;
                } else {
                    sortOrderTable = TableParam.SortOrder.DESCENDING;
                }
            }
        }
        // FOR IMMEDIATE AND RECCURING TRANSACTION
        // PUT FILTER != FUTURE_DATE
        filters.put("instructionMode", "FUTURE_DATE");
        TableParam tableParam = new TableParam(pageSize, first, sortField, sortOrderTable, filters);
        TableResult<ForeignTransferRequestTableView> result = foreignTransferRequestTableViewRepository.findByFilters(tableParam);
        setRowCount(result.getRowCount().intValue());
        LOG.info("### COUNT DATA : {} ###", result.getRowCount().intValue());
        return result.getData();
        
    }
    
    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }
    
}