Project

General

Profile

Download (3.25 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

    
10
package eu.etaxonomy.taxeditor.newWizard;
11

    
12
import java.util.HashSet;
13
import java.util.Set;
14

    
15
import eu.etaxonomy.cdm.api.service.INameService;
16
import eu.etaxonomy.cdm.api.service.ITaxonService;
17
import eu.etaxonomy.cdm.model.name.HybridRelationship;
18
import eu.etaxonomy.cdm.model.name.TaxonName;
19
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
20
import eu.etaxonomy.cdm.model.taxon.Taxon;
21
import eu.etaxonomy.taxeditor.store.CdmStore;
22
import eu.etaxonomy.taxeditor.ui.section.name.NonViralNameWizardPage;
23
import eu.etaxonomy.taxeditor.ui.section.taxon.TaxonWizardPage;
24

    
25
/**
26
 *
27
 * @author pplitzner
28
 * @date Jan 18, 2016
29
 *
30
 */
31
public class NewTaxonWizard extends AbstractNewEntityWizard<Taxon> {
32

    
33
	/** {@inheritDoc} */
34
	@Override
35
	public void addPages() {
36
	    addPage(new TaxonWizardPage(formFactory, getConversationHolder(), getEntity()));
37
	    addPage(new NonViralNameWizardPage(formFactory, getConversationHolder(), getEntity().getName()));
38
	}
39

    
40
	/** {@inheritDoc} */
41
	@Override
42
	protected Taxon createNewEntity() {
43
		return Taxon.NewInstance(TaxonNameFactory.NewNonViralInstance(null), null);
44
	}
45

    
46
	/** {@inheritDoc} */
47
	@Override
48
	protected void saveEntity() {
49
// TODO: if new entity is an hybrid, the hybrid names should be saved first.. see newTaxonnodeWizard
50
	    Taxon taxon = getEntity();
51
	    if (!taxon.getName().getHybridChildRelations().isEmpty() || !taxon.getName().getHybridParentRelations().isEmpty()){
52
            Set<TaxonName> namesToSave = new HashSet<>();
53
            for (HybridRelationship hybridRelationship: taxon.getName().getHybridChildRelations()){
54
                if (hybridRelationship.getParentName() != taxon.getName()){
55
                    if (!hybridRelationship.getParentName().isPersited()){
56
                        namesToSave.add(hybridRelationship.getParentName());
57
                    }
58
               }else if (hybridRelationship.getHybridName() != taxon.getName()){
59
                   if (!hybridRelationship.getHybridName().isPersited()){
60
                       namesToSave.add(hybridRelationship.getHybridName());
61
                   }
62
                }
63

    
64
            }
65

    
66
            for (HybridRelationship hybridRelationship: taxon.getName().getHybridParentRelations()){
67
                if (hybridRelationship.getParentName() != taxon.getName()){
68
                    if (!hybridRelationship.getParentName().isPersited()){
69
                        namesToSave.add(hybridRelationship.getParentName());
70
                    }
71
               }else if (hybridRelationship.getHybridName() != taxon.getName()){
72
                   if (!hybridRelationship.getHybridName().isPersited()){
73
                       namesToSave.add(hybridRelationship.getHybridName());
74
                   }
75
                }
76

    
77
            }
78
            CdmStore.getService(INameService.class).save(namesToSave);
79
        }
80
	    CdmStore.getService(ITaxonService.class).save(taxon);
81
	}
82

    
83
	/** {@inheritDoc} */
84
	@Override
85
	public void setEntity(Taxon entity) {
86
		super.setEntity(entity);
87
	}
88

    
89
	@Override
90
	protected String getEntityName() {
91
		return "Taxon";
92
	}
93
}
(22-22/27)