/* Demoiselle Framework Copyright (C) 2013 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 versão 3 como publicada pela Fundação do Software Livre (FSF). Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português para maiores detalhes. Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> ou escreva para a Fundação do Software Livre (FSF) Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. */ package org.demoiselle.estacionamento.business; import java.util.logging.Logger; import javax.inject.Inject; import org.demoiselle.estacionamento.config.EstacionamentoConfig; import org.demoiselle.estacionamento.domain.Estacionamento; import org.demoiselle.estacionamento.message.ErrorMessages; import org.demoiselle.estacionamento.message.InfoMessages; import org.demoiselle.estacionamento.persistence.EstacionamentoDAO; import br.gov.frameworkdemoiselle.exception.ExceptionHandler; import br.gov.frameworkdemoiselle.lifecycle.Startup; import br.gov.frameworkdemoiselle.message.MessageContext; import br.gov.frameworkdemoiselle.message.SeverityType; import br.gov.frameworkdemoiselle.security.RequiredPermission; import br.gov.frameworkdemoiselle.security.RequiredRole; import br.gov.frameworkdemoiselle.stereotype.BusinessController; import br.gov.frameworkdemoiselle.template.DelegateCrud; import br.gov.frameworkdemoiselle.transaction.Transactional; @BusinessController public class EstacionamentoBC extends DelegateCrud<Estacionamento, Long, EstacionamentoDAO> { private static final long serialVersionUID = 1L; @Inject private EstacionamentoConfig config; @Inject private MessageContext messageContext; @Inject private Logger logger; @ExceptionHandler public void tratador(NullPointerException cause) { messageContext.add(ErrorMessages.NULL_POINTER.getText(), cause.getMessage(), SeverityType.ERROR); } @ExceptionHandler public void seguranca(SecurityException cause) { messageContext.add(ErrorMessages.ACESSO_NOK.getText(), cause.getMessage()); } @Startup @Transactional public void startup() { // Para ativar essa configuração modifique o valor em estacionamento.properties -> general.loadInitialData = // true if (config.isLoadInitialData()) { logger.info("Carregando..........." ); if (findAll().isEmpty()) { insert(new Estacionamento("Demoiselle Park", "42070027000109", " 0775037176397")); } } } @Override @Transactional // Não é possível com JAAS. @RequiredPermission(resource = "estacionamento", operation = "insert") //@RequiredRole({"gerente","atendente"}) public Estacionamento insert(Estacionamento estacionamento) { try { super.insert(estacionamento); messageContext.add(InfoMessages.ESTACIONAMENTO_INSERT_OK.getText(), estacionamento.getNome()); } catch (Exception te) { te.printStackTrace(); messageContext.add(ErrorMessages.ESTACIONAMENTO_INSERT_NOK.getText(), te.getMessage(), SeverityType.ERROR); } return estacionamento; } @Override @Transactional // Não é possível com JAAS. @RequiredPermission(resource = "estacionamento", operation = "update") //@RequiredRole({"gerente","atendente"}) public Estacionamento update(Estacionamento estacionamento) { try { super.update(estacionamento); messageContext.add(InfoMessages.ESTACIONAMENTO_UPDATE_OK.getText(), estacionamento.getNome()); } catch (Exception te) { messageContext.add(ErrorMessages.ESTACIONAMENTO_UPDATE_NOK.getText(), te.getMessage(), SeverityType.ERROR); } return estacionamento; } @Override @Transactional @RequiredRole("gerente") public void delete(Long id) { try { super.delete(id); messageContext.add(InfoMessages.ESTACIONAMENTO_DELETE_OK.getText(), id); } catch (Exception te) { messageContext.add(ErrorMessages.ESTACIONAMENTO_DELETE_NOK.getText(), te.getMessage(), SeverityType.ERROR); } } }