import eu.etaxonomy.cdm.api.service.IService;
import eu.etaxonomy.cdm.api.service.ITestService;
import eu.etaxonomy.cdm.io.service.IIOService;
+import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.taxeditor.service.ICachedCommonService;
+import eu.etaxonomy.taxeditor.session.DefaultNewEntityListener;
/**
* @author cmathew
public static CdmApplicationState getInstance() {
if(cdmApplicationState == null) {
cdmApplicationState = new CdmApplicationState();
+ CdmBase.setNewEntityListener(new DefaultNewEntityListener());
}
return cdmApplicationState;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.UUID;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
private final CacheLoader cacheLoader;
-
+ private final Map<UUID, CdmBase> newEntitiesMap = new HashMap<UUID, CdmBase>();
public CdmTransientEntityCacher(String cacheId, ICdmEntitySessionManager cdmEntitySessionManager) {
this.cacheId = cacheId;
this.cdmEntitySessionManager = cdmEntitySessionManager;
cacheLoader = new CacheLoader(this);
+
}
public CdmTransientEntityCacher(Object sessionOwner, ICdmEntitySessionManager cdmEntitySessionManager) {
}
-
+ public void addNewEntity(CdmBase newEntity) {
+ if(newEntity != null && newEntity.getId() == 0 && newEntity.getUuid() != null) {
+ newEntitiesMap.put(newEntity.getUuid(), newEntity);
+ }
+ }
@Override
public void put(CdmBase cdmEntity) {
cachedCdmEntity = getFromCache(id);
if(cachedCdmEntity == null) {
- getCache().put(new Element(id, cdmEntity));
- cdmEntity.initListener();
- logger.info(" - object of type " + cdmEntity.getClass().getName() + " with id " + cdmEntity.getId() + " put in cache");
+ CdmBase cdmEntityToCache = cdmEntity;
+ CdmBase newEntity = newEntitiesMap.get(cdmEntity.getUuid());
+ if(newEntity != null) {
+ newEntity.setId(cdmEntity.getId());
+ cdmEntityToCache = newEntity;
+ }
+ getCache().put(new Element(id, cdmEntityToCache));
+ cdmEntityToCache.initListener();
+ newEntitiesMap.remove(cdmEntity.getUuid());
+ logger.info(" - object of type " + cdmEntityToCache.getClass().getName() + " with id " + cdmEntityToCache.getId() + " put in cache");
return;
}
logger.info(" - object of type " + cdmEntity.getClass().getName() + " with id " + cdmEntity.getId() + " already exists");
public void dispose() {
CacheManager.create().removeCache(cache.getName());
cache.dispose();
+ newEntitiesMap.clear();
}
+
/* (non-Javadoc)
* @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#load(java.lang.Object, boolean)
*/
return propertyPathsMap.get(obj);
}
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#addNewCdmEntity(eu.etaxonomy.cdm.model.common.CdmBase)
+ */
+ @Override
+ public void addNewCdmEntity(CdmBase newEntity) {
+ cdmTransientEntityCacher.addNewEntity(newEntity);
+ }
+
}
--- /dev/null
+// $Id$
+/**
+* Copyright (C) 2015 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.session;
+
+import org.apache.log4j.Logger;
+
+import eu.etaxonomy.cdm.api.application.CdmApplicationRemoteController;
+import eu.etaxonomy.cdm.api.application.CdmApplicationState;
+import eu.etaxonomy.cdm.model.NewEntityListener;
+import eu.etaxonomy.cdm.model.common.CdmBase;
+
+/**
+ * @author cmathew
+ * @date 30 Sep 2015
+ *
+ */
+public class DefaultNewEntityListener implements NewEntityListener {
+
+ private static final Logger logger = Logger.getLogger(DefaultNewEntityListener.class);
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.cdm.model.NewEntityListener#onCreate(eu.etaxonomy.cdm.model.common.CdmBase)
+ */
+ @Override
+ public void onCreate(CdmBase cdmBase) {
+ logger.warn("New Entity created : " + cdmBase);
+ ((CdmApplicationRemoteController)CdmApplicationState.getCurrentAppConfig()).getCdmEntitySessionManager().getActiveSession().addNewCdmEntity(cdmBase);
+ }
+
+}
*/
public List<String> getPropertyPaths(Object obj);
+ public void addNewCdmEntity(CdmBase newEntity);
+
}
\ No newline at end of file
return propertyPathsMap.get(obj);
}
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#addNewCdmEntity(eu.etaxonomy.cdm.model.common.CdmBase)
+ */
+ @Override
+ public void addNewCdmEntity(CdmBase newEntity) {
+ // TODO Auto-generated method stub
+
+ }
+
}
return null;
}
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#addNewCdmEntity(eu.etaxonomy.cdm.model.common.CdmBase)
+ */
+ @Override
+ public void addNewCdmEntity(CdmBase newEntity) {
+ // TODO Auto-generated method stub
+
+ }
+
}
import org.apache.log4j.Logger;
import org.eclipse.core.commands.ExecutionException;
import org.junit.Assert;
+import org.junit.Ignore;
import org.junit.Test;
import org.unitils.dbunit.annotation.DataSet;
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
import eu.etaxonomy.cdm.api.service.ITaxonService;
import eu.etaxonomy.cdm.model.common.Language;
+import eu.etaxonomy.cdm.model.common.OriginalSourceType;
+import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
+import eu.etaxonomy.cdm.model.description.Feature;
+import eu.etaxonomy.cdm.model.description.TaxonDescription;
+import eu.etaxonomy.cdm.model.description.TextData;
import eu.etaxonomy.cdm.model.name.BotanicalName;
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
import eu.etaxonomy.cdm.model.name.NonViralName;
import eu.etaxonomy.cdm.model.taxon.Taxon;
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
import eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation;
+import eu.etaxonomy.taxeditor.store.CdmStore;
/**
* @author cmathew
taxonService.merge(taxon);
}
+ @Ignore
+ @Test
+ public void addDescription() {
+ UUID taxonNodeUuid = UUID.fromString("ce54c396-3694-47f2-abb0-1d7b7e057985");
+
+ TaxonNode taxonNode = taxonNodeService.load(taxonNodeUuid);
+ Taxon taxon = taxonNode.getTaxon();
+ TaxonDescription description = TaxonDescription.NewInstance(taxon);
+
+
+ TextData textData = TextData.NewInstance();
+
+ textData.setFeature(Feature.ECOLOGY());
+ description.addElement(textData);
+
+ DescriptionElementSource descriptionElementSource = DescriptionElementSource.NewInstance(OriginalSourceType.PrimaryTaxonomicSource);
+ textData.addSource(descriptionElementSource);
+
+
+ CdmStore.getService(ITaxonNodeService.class).merge(taxonNode);
+
+ description.getId();
+ }
+
+
+ @Test
+ public void addTaxonNodeCascadeProblem() {
+ UUID taxonNodeUuid = UUID.fromString("ce54c396-3694-47f2-abb0-1d7b7e057985");
+
+ TaxonNode taxonNode = taxonNodeService.load(taxonNodeUuid);
+ Taxon childTaxon = Taxon.NewInstance(null, null);
+ TaxonNode childTaxonNode = taxonNode.addChildTaxon(childTaxon, null, null);
+ Taxon grandChildTaxon = Taxon.NewInstance(null, null);
+ TaxonNode grandChildTaxonNode = childTaxonNode.addChildTaxon(grandChildTaxon, null, null);
+
+ CdmStore.getService(ITaxonNodeService.class).merge(taxonNode, true);
+
+ Assert.assertEquals(taxonNode.getChildNodes().get(0).getId(), childTaxonNode.getId());
+ Assert.assertEquals(taxonNode.getChildNodes().get(0).getTaxon().getId(), childTaxon.getId());
+ Assert.assertEquals(taxonNode.getChildNodes().get(0).getChildNodes().get(0).getId(), grandChildTaxonNode.getId());
+ Assert.assertEquals(taxonNode.getChildNodes().get(0).getChildNodes().get(0).getTaxon().getId(), grandChildTaxon.getId());
+ }
+
}
pKey = polytomousKeyService.merge(pKey, true);
grandChildNode = pKey.getRoot().getChildAt(0).getChildAt(0);
Assert.assertTrue(0 != grandChildNode.getId());
-
- grandChildNode.setStatement(KeyStatement.NewInstance("test"));
+ KeyStatement ks = KeyStatement.NewInstance("test");
+ grandChildNode.setStatement(ks);
pKey = polytomousKeyService.merge(pKey, true);
- grandChildNode = pKey.getRoot().getChildAt(0).getChildAt(0);
- KeyStatement ks = grandChildNode.getStatement();
+ //grandChildNode = pKey.getRoot().getChildAt(0).getChildAt(0);
+ //KeyStatement ks = grandChildNode.getStatement();
Assert.assertTrue(0 != ks.getId());
}
rootChildNode.addChild(grandChildNode);
- grandChildNode = polytomousKeyNodeService.merge(grandChildNode);
+ polytomousKeyNodeService.merge(grandChildNode);
- PolytomousKeyNode greatGrandChildNode = PolytomousKeyNode.NewInstance();
- grandChildNode.addChild(greatGrandChildNode);
Assert.assertFalse(pKey.getRoot().getChildAt(0).getChildAt(0).getId() == 0);
}
<SynonymRelationship id="50" created="2010-12-21 15:09:45.0" uuid="60d1466f-5823-4a69-a071-1887d0c1e72b" doubtful="false" partial="false" proparte="false" relatedfrom_id="388" relatedto_id="387" />
<LanguageString id="10"/>
+ <DescriptionBase/>
+ <DescriptionElementBase/>
</dataset>