package eu.etaxonomy.taxeditor.newWizard;
+import java.util.HashSet;
+import java.util.Set;
+
+import eu.etaxonomy.cdm.api.service.INameService;
import eu.etaxonomy.cdm.api.service.ITaxonService;
+import eu.etaxonomy.cdm.model.name.HybridRelationship;
+import eu.etaxonomy.cdm.model.name.TaxonName;
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
import eu.etaxonomy.cdm.model.taxon.Taxon;
import eu.etaxonomy.taxeditor.store.CdmStore;
/** {@inheritDoc} */
@Override
protected void saveEntity() {
- CdmStore.getService(ITaxonService.class).save(getEntity());
+// TODO: if new entity is an hybrid, the hybrid names should be saved first.. see newTaxonnodeWizard
+ Taxon taxon = getEntity();
+ if (!taxon.getName().getHybridChildRelations().isEmpty() || !taxon.getName().getHybridParentRelations().isEmpty()){
+ Set<TaxonName> namesToSave = new HashSet<>();
+ for (HybridRelationship hybridRelationship: taxon.getName().getHybridChildRelations()){
+ if (hybridRelationship.getParentName() != taxon.getName()){
+ if (!hybridRelationship.getParentName().isPersited()){
+ namesToSave.add(hybridRelationship.getParentName());
+ }
+ }else if (hybridRelationship.getHybridName() != taxon.getName()){
+ if (!hybridRelationship.getHybridName().isPersited()){
+ namesToSave.add(hybridRelationship.getHybridName());
+ }
+ }
+
+ }
+
+ for (HybridRelationship hybridRelationship: taxon.getName().getHybridParentRelations()){
+ if (hybridRelationship.getParentName() != taxon.getName()){
+ if (!hybridRelationship.getParentName().isPersited()){
+ namesToSave.add(hybridRelationship.getParentName());
+ }
+ }else if (hybridRelationship.getHybridName() != taxon.getName()){
+ if (!hybridRelationship.getHybridName().isPersited()){
+ namesToSave.add(hybridRelationship.getHybridName());
+ }
+ }
+
+ }
+ CdmStore.getService(INameService.class).save(namesToSave);
+ }
+ CdmStore.getService(ITaxonService.class).save(taxon);
}
/** {@inheritDoc} */