Index: topia-security/src/java/org/codelutin/topia/history/TopiaHistoryServiceImpl.java diff -u topia-security/src/java/org/codelutin/topia/history/TopiaHistoryServiceImpl.java:1.2 topia-security/src/java/org/codelutin/topia/history/TopiaHistoryServiceImpl.java:1.3 --- topia-security/src/java/org/codelutin/topia/history/TopiaHistoryServiceImpl.java:1.2 Wed Oct 18 08:46:34 2006 +++ topia-security/src/java/org/codelutin/topia/history/TopiaHistoryServiceImpl.java Tue Oct 24 12:01:00 2006 @@ -23,9 +23,9 @@ * Created: 14 oct. 06 00:54:35 * * @author poussin - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ * - * Last update: $Date: 2006/10/18 08:46:34 $ + * Last update: $Date: 2006/10/24 12:01:00 $ * by : $Author: ruchaud $ */ @@ -47,6 +47,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.codelutin.topia.TopiaContext; +import org.codelutin.topia.event.TopiaTransactionEvent; +import org.codelutin.topia.event.TopiaTransactionVetoable; import org.codelutin.topia.framework.TopiaContextImplementor; import org.codelutin.topia.history.entities.HistoryImpl; import org.codelutin.topia.security.util.TopiaSecurityUtil; @@ -54,6 +56,7 @@ import org.hibernate.FlushMode; import org.hibernate.ScrollableResults; import org.hibernate.criterion.Order; +import org.hibernate.criterion.Projections; import org.hibernate.criterion.Property; import org.hibernate.criterion.Restrictions; @@ -95,7 +98,7 @@ * * @author poussin */ -public class TopiaHistoryServiceImpl implements TopiaHistoryService, Runnable { +public class TopiaHistoryServiceImpl implements TopiaHistoryService, Runnable, TopiaTransactionVetoable { /** to use log facility, just put in your code: log.info(\"...\"); */ static private Log log = LogFactory.getLog(TopiaHistoryServiceImpl.class); @@ -106,15 +109,15 @@ static final private int FIELD_TYPE = 3; static final private int FIELD_TARGET = 4; - static private final String HISTORY_CREATE_KEY = "topia.history.create"; - static private final String HISTORY_DELETE_KEY = "topia.history.delete"; - static private final String HISTORY_UPDATE_KEY = "topia.history.update"; - static private final String HISTORY_LOAD_KEY = "topia.history.load"; + static private final String HISTORY_CREATE_KEY = "topia.service.history.create"; + static private final String HISTORY_DELETE_KEY = "topia.service.history.delete"; + static private final String HISTORY_UPDATE_KEY = "topia.service.history.update"; + static private final String HISTORY_LOAD_KEY = "topia.service.history.load"; - static private final String HISTORY_CLEAN_FREQUENCY_KEY = "topia.history.clean.frequency"; - static private final String HISTORY_CLEAN_DATE_KEY = "topia.history.clean.date"; - static private final String HISTORY_CLEAN_NUMBER_KEY = "topia.history.clean.number"; - static private final String HISTORY_STORE_FILE_KEY = "topia.history.store.file"; + static private final String HISTORY_CLEAN_FREQUENCY_KEY = "topia.service.history.clean.frequency"; + static private final String HISTORY_CLEAN_DATE_KEY = "topia.service.history.clean.date"; + static private final String HISTORY_CLEAN_NUMBER_KEY = "topia.service.history.clean.number"; + static private final String HISTORY_STORE_FILE_KEY = "topia.service.history.store.file"; protected TopiaHistoryListener historyListener = null; @@ -161,6 +164,8 @@ historyListener = new TopiaHistoryListener(context, historyCreate, historyDelete, historyUpdate, historyLoad); + context.addTopiaEntityListener(historyListener); + context.addTopiaTransactionVetoable(this); cleanFrequency = Float.parseFloat(config.getProperty(HISTORY_CLEAN_FREQUENCY_KEY, ""+cleanFrequency)); cleanDate = Integer.parseInt(config.getProperty(HISTORY_CLEAN_DATE_KEY, ""+cleanDate)); @@ -185,6 +190,15 @@ } } + /** + * Permet de propager le l'historisation sur l'ensemble des contextes + */ + public void beginTransaction(TopiaTransactionEvent event) { + TopiaContext context = event.getSource(); + context.addTopiaEntityListener(historyListener); + context.addTopiaTransactionVetoable(this); + } + /* (non-Javadoc) * @see org.codelutin.topia.security.entities.authorization.History#clear(java.util.Date) */ @@ -244,16 +258,15 @@ criteria.add( Restrictions.in("action", Arrays.asList(actions))); if (user != null) { - criteria.add( Restrictions.eq("user", user)); + criteria.add( Restrictions.eq("userId", user)); } if (type != null) { criteria.add( Restrictions.in("type", new String[]{type, type + "Impl"})); } - List result = new ArrayList(); - - ScrollableResults histories = criteria.scroll(); + + ScrollableResults histories = criteria.scroll(); for (int i=limit; i == 0 && histories.next(); i--) { result.add(histories.getString(FIELD_TARGET)); } @@ -306,7 +319,7 @@ } log.info("End history schuduling"); } - + } Index: topia-security/src/java/org/codelutin/topia/history/TopiaHistoryListener.java diff -u topia-security/src/java/org/codelutin/topia/history/TopiaHistoryListener.java:1.2 topia-security/src/java/org/codelutin/topia/history/TopiaHistoryListener.java:1.3 --- topia-security/src/java/org/codelutin/topia/history/TopiaHistoryListener.java:1.2 Wed Oct 18 08:46:34 2006 +++ topia-security/src/java/org/codelutin/topia/history/TopiaHistoryListener.java Tue Oct 24 12:01:00 2006 @@ -23,16 +23,17 @@ * Created: 13 oct. 06 21:31:23 * * @author poussin - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ * - * Last update: $Date: 2006/10/18 08:46:34 $ + * Last update: $Date: 2006/10/24 12:01:00 $ * by : $Author: ruchaud $ */ package org.codelutin.topia.history; -import java.util.Collection; +import java.util.Arrays; import java.util.Date; +import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -41,11 +42,10 @@ import org.codelutin.topia.TopiaServiceDAOHelper; import org.codelutin.topia.event.TopiaEntityEvent; import org.codelutin.topia.event.TopiaEntityListener; -import org.codelutin.topia.event.TopiaEntityLoadEvent; -import org.codelutin.topia.event.TopiaEntityLoadListener; import org.codelutin.topia.history.entities.History; import org.codelutin.topia.history.entities.HistoryDAO; import org.codelutin.topia.persistence.TopiaEntity; +import org.codelutin.topia.security.listener.NoEntityVetoableRead; import org.codelutin.topia.security.util.TopiaSecurityUtil; @@ -53,8 +53,7 @@ * * @author poussin */ -public class TopiaHistoryListener implements TopiaEntityListener, - TopiaEntityLoadListener { +public class TopiaHistoryListener implements TopiaEntityListener { /** to use log facility, just put in your code: log.info(\"...\"); */ static private Log log = LogFactory.getLog(TopiaHistoryListener.class); @@ -79,61 +78,59 @@ /* (non-Javadoc) * @see org.codelutin.topia.event.TopiaEntityListener#entityCreated(org.codelutin.topia.event.TopiaEntityEvent) */ - public void entityCreated(TopiaEntityEvent e) { + public void create(TopiaEntityEvent e) { if (historyCreate) { - Collection entities = e.getTopiaEntities(); - addToHistory(entities, TopiaSecurityUtil.CREATE); + TopiaEntity entity = e.getEntity(); + addToHistory(entity, TopiaSecurityUtil.CREATE); } } /* (non-Javadoc) * @see org.codelutin.topia.event.TopiaEntityListener#entityDeleted(org.codelutin.topia.event.TopiaEntityEvent) */ - public void entityDeleted(TopiaEntityEvent e) { + public void delete(TopiaEntityEvent e) { if (historyDelete) { - Collection entities = e.getTopiaEntities(); - addToHistory(entities, TopiaSecurityUtil.DELETE); + TopiaEntity entity = e.getEntity(); + addToHistory(entity, TopiaSecurityUtil.DELETE); } } /* (non-Javadoc) * @see org.codelutin.topia.event.TopiaEntityListener#entityUpdated(org.codelutin.topia.event.TopiaEntityEvent) */ - public void entityUpdated(TopiaEntityEvent e) { + public void update(TopiaEntityEvent e) { if (historyUpdate) { - Collection entities = e.getTopiaEntities(); - addToHistory(entities, TopiaSecurityUtil.UPDATE); + TopiaEntity entity = e.getEntity(); + addToHistory(entity, TopiaSecurityUtil.UPDATE); } } /* (non-Javadoc) * @see org.codelutin.topia.event.TopiaEntityLoadListener#entityLoaded(org.codelutin.topia.event.TopiaEntityLoadEvent) */ - public void entityLoaded(TopiaEntityLoadEvent e) { + public void load(TopiaEntityEvent e) { if (historyLoad) { - Collection entities = e.getTopiaEntities(); - addToHistory(entities, TopiaSecurityUtil.LOAD); + TopiaEntity entity = e.getEntity(); + addToHistory(entity, TopiaSecurityUtil.LOAD); } } - protected void addToHistory(Collection entities, int action) { - if (entities.size() > 0) { + protected void addToHistory(TopiaEntity entity, int action) { + Class[] interfaces = entity.getClass().getInterfaces(); + List asList = Arrays.asList(interfaces); + if (!asList.contains(NoHistory.class)) { String user = TopiaSecurityUtil.getUserPrincipal(); Date date = new Date(); try { TopiaContext tx = context.beginTransaction(); HistoryDAO dao = TopiaServiceDAOHelper.getHistoryDAO(tx); - for (Object o : entities) { - if (o instanceof TopiaEntity) { - String target = ((TopiaEntity)o).getTopiaId(); - - History history = dao.create(); - history.setActionDate(date); - history.setUserId(user); - history.setAction(action); - history.setTypeAndTarget(target); - } - } + + History history = dao.create(); + history.setActionDate(date); + history.setUserId(user); + history.setAction(action); + history.setTypeAndTarget(entity.getTopiaId()); + tx.commitTransaction(); tx.closeContext(); } catch (TopiaException eee) { @@ -145,5 +142,3 @@ } } - - Index: topia-security/src/java/org/codelutin/topia/history/NoHistory.java diff -u /dev/null topia-security/src/java/org/codelutin/topia/history/NoHistory.java:1.1 --- /dev/null Tue Oct 24 12:01:05 2006 +++ topia-security/src/java/org/codelutin/topia/history/NoHistory.java Tue Oct 24 12:01:00 2006 @@ -0,0 +1,39 @@ +/* *##% + * Copyright (C) 2006 + * Code Lutin, Cédric Pineau, Benjamin Poussin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * 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 General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +/* * + * NoHistory.java + * + * Created: 16 oct. 06 19:45:01 + * + * @author poussin + * @version $Revision: 1.1 $ + * + * Last update: $Date: 2006/10/24 12:01:00 $ + * by : $Author: ruchaud $ + */ + +package org.codelutin.topia.history; + +/** + * Permet préciser qu'une entité ne doit pas apparaitre dans l'historique + */ +public interface NoHistory { + +}