Add check to make sure active session is not null
[taxeditor.git] / eu.etaxonomy.taxeditor.cdmlib / src / main / java / eu / etaxonomy / taxeditor / session / DefaultNewEntityListener.java
1 // $Id$
2 /**
3 * Copyright (C) 2015 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10 package eu.etaxonomy.taxeditor.session;
11
12 import org.apache.log4j.Logger;
13
14 import eu.etaxonomy.cdm.api.application.CdmApplicationRemoteController;
15 import eu.etaxonomy.cdm.api.application.CdmApplicationState;
16 import eu.etaxonomy.cdm.model.NewEntityListener;
17 import eu.etaxonomy.cdm.model.common.CdmBase;
18
19 /**
20 * @author cmathew
21 * @date 30 Sep 2015
22 *
23 */
24 public class DefaultNewEntityListener implements NewEntityListener {
25
26 private static final Logger logger = Logger.getLogger(DefaultNewEntityListener.class);
27
28 /* (non-Javadoc)
29 * @see eu.etaxonomy.cdm.model.NewEntityListener#onCreate(eu.etaxonomy.cdm.model.common.CdmBase)
30 */
31 @Override
32 public void onCreate(CdmBase cdmBase) {
33 logger.info("New Entity created : " + cdmBase);
34 if(CdmApplicationState.getCurrentAppConfig() instanceof CdmApplicationRemoteController){
35 ICdmEntitySession activeSession = ((CdmApplicationRemoteController)CdmApplicationState.getCurrentAppConfig()).getCdmEntitySessionManager().getActiveSession();
36 if(activeSession != null) {
37 activeSession.addNewCdmEntity(cdmBase);
38 }
39 }
40 }
41
42 }