br.gov.frameworkdemoiselle.component.audit.dashboard.view.FeaturesDashboardMB.java Source code

Java tutorial

Introduction

Here is the source code for br.gov.frameworkdemoiselle.component.audit.dashboard.view.FeaturesDashboardMB.java

Source

/*
 * Demoiselle Framework
 * Copyright (C) 2014 SERPRO
 * ----------------------------------------------------------------------------
 * This file is part of Demoiselle Framework.
 * 
 * Demoiselle Framework is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License version 3
 * as published by the Free Software Foundation.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License version 3
 * along with this program; if not,  see <http://www.gnu.org/licenses/>
 * or write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA  02110-1301, USA.
 * ----------------------------------------------------------------------------
 * Este arquivo  parte do Framework Demoiselle.
 * 
 * O Framework Demoiselle  um software livre; voc pode redistribu-lo e/ou
 * modific-lo dentro dos termos da GNU LGPL verso 3 como publicada pela Fundao
 * do Software Livre (FSF).
 * 
 * Este programa  distribudo na esperana que possa ser til, mas SEM NENHUMA
 * GARANTIA; sem uma garantia implcita de ADEQUAO a qualquer MERCADO ou
 * APLICAO EM PARTICULAR. Veja a Licena Pblica Geral GNU/LGPL em portugus
 * para maiores detalhes.
 * 
 * Voc deve ter recebido uma cpia da GNU LGPL verso 3, sob o ttulo
 * "LICENCA.txt", junto com esse programa. Se no, acesse <http://www.gnu.org/licenses/>
 * ou escreva para a Fundao do Software Livre (FSF) Inc.,
 * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
 */
package br.gov.frameworkdemoiselle.component.audit.dashboard.view;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import javax.annotation.PostConstruct;

import org.apache.commons.collections.ListUtils;
import org.primefaces.extensions.component.masterdetail.SelectLevelEvent;
import org.primefaces.extensions.component.timeline.TimelineUpdater;
import org.primefaces.extensions.event.timeline.TimelineLazyLoadEvent;
import org.primefaces.extensions.model.timeline.TimelineEvent;

import br.gov.frameworkdemoiselle.component.audit.dashboard.domain.Feature;
import br.gov.frameworkdemoiselle.component.audit.domain.Trail;

/**
 * 
 * @author SERPRO
 * 
 */

public class FeaturesDashboardMB extends DashboardMB {

    private static final long serialVersionUID = 1L;

    private List<Feature> featureList;

    private Feature feature;

    public FeaturesDashboardMB() {
    }

    @PostConstruct
    public void initialize() {

        featureList = new ArrayList<Feature>();

        for (String feature : trailBC.findByNamedQueryDistinct("Trail.findDistinctWhat")) {
            featureList.add(new Feature(feature));
        }
    }

    @Override
    public Integer navigationHadler(SelectLevelEvent e) {

        Integer nextLevel = e.getNewLevel();

        if (nextLevel == 1) {
            initialize();
        } else {
            search();
            fillFeatures();
        }

        return nextLevel;
    }

    private void search() {
        Calendar dateBegin = Calendar.getInstance();
        dateBegin.set(Calendar.DAY_OF_MONTH, dateBegin.get(Calendar.DAY_OF_MONTH) - 5);
        dateBegin.set(Calendar.HOUR_OF_DAY, 0);
        dateBegin.set(Calendar.MINUTE, 0);
        dateBegin.set(Calendar.SECOND, 0);

        Calendar dataFinal = Calendar.getInstance();
        dataFinal.set(Calendar.HOUR_OF_DAY, 23);
        dataFinal.set(Calendar.MINUTE, 59);
        dataFinal.set(Calendar.SECOND, 59);

        trails = trailBC.findByNamedQueryWithBetween("Trail.findByWhat", "what", feature.getWhat(),
                dateBegin.getTime(), dataFinal.getTime());
    }

    @SuppressWarnings("unchecked")
    public void onLazyLoad(TimelineLazyLoadEvent e) {

        Date dataInicio = e.getStartDateFirst();
        Date dataFinal = e.getEndDateFirst();

        TimelineUpdater timelineUpdater = TimelineUpdater.getCurrentInstance(":formTabs:tabs:timelineFeature");

        trails = ListUtils.subtract(trailBC.findByNamedQueryWithBetween("Trail.findByWhat", "what",
                feature.getWhat(), dataInicio, dataFinal), trails);

        for (Trail trail : trails) {
            this.features.add(new TimelineEvent(trail, trail.getWhen(), false), timelineUpdater);
        }

    }

    public void setFeature(Object feature) {
        this.feature = (Feature) feature;
    }

    public List<Feature> getFeaturesList() {
        return featureList;
    }

    public Feature getFeature() {
        return feature;
    }

}