Java tutorial
/* * 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.User; import br.gov.frameworkdemoiselle.component.audit.domain.Trail; /** * * @author SERPRO * */ public class UsersDashboardMB extends DashboardMB { private static final long serialVersionUID = 1L; private List<User> usersList; private User user; @PostConstruct public void initialize() { usersList = new ArrayList<User>(); for (String user : trailBC.findByNamedQueryDistinct("Trail.findDistinctUserName")) { usersList.add(new User(user)); } } @Override public Integer navigationHadler(SelectLevelEvent e) { Integer nextLevel = e.getNewLevel(); if (nextLevel == 1) { initialize(); } else { search(); fillUsers(); } 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 dateFinal = Calendar.getInstance(); dateFinal.set(Calendar.HOUR_OF_DAY, 23); dateFinal.set(Calendar.MINUTE, 59); dateFinal.set(Calendar.SECOND, 59); trails = trailBC.findByNamedQueryWithBetween("Trail.findByUserName", "userName", user.getUserName(), dateBegin.getTime(), dateFinal.getTime()); } @SuppressWarnings("unchecked") public void onLazyLoad(TimelineLazyLoadEvent e) { Date dateBegin = e.getStartDateFirst(); Date dateFinal = e.getEndDateFirst(); TimelineUpdater timelineUpdater = TimelineUpdater.getCurrentInstance(":formTabs:tabs:timelineUser"); trails = ListUtils.subtract(trailBC.findByNamedQueryWithBetween("Trail.findByUserName", "userName", user.getUserName(), dateBegin, dateFinal), trails); for (Trail trail : trails) { this.users.add(new TimelineEvent(trail, trail.getWhen(), false), timelineUpdater); } } public void setUser(Object object) { this.user = (User) object; } public List<User> getUsersList() { return usersList; } public User getUser() { return user; } }