Project

General

Profile

Download (4.36 KB) Statistics
| Branch: | Tag: | Revision:
1
package eu.etaxonomy.taxeditor.bulkeditor.input;
2

    
3
import java.util.ArrayList;
4
import java.util.Arrays;
5
import java.util.List;
6
import java.util.UUID;
7

    
8
import eu.etaxonomy.cdm.api.service.ITaxonService;
9
import eu.etaxonomy.cdm.api.service.config.DeleteConfiguratorBase;
10
import eu.etaxonomy.cdm.api.service.config.FindTaxaAndNamesConfiguratorImpl;
11
import eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator;
12
import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
13
import eu.etaxonomy.cdm.api.service.config.SynonymDeletionConfigurator;
14
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
15
import eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException;
16
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
17
import eu.etaxonomy.cdm.model.taxon.Synonym;
18
import eu.etaxonomy.cdm.model.taxon.Taxon;
19
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
20
import eu.etaxonomy.cdm.persistence.query.MatchMode;
21
import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator;
22
import eu.etaxonomy.taxeditor.bulkeditor.input.entitycreator.TaxonCreator;
23
import eu.etaxonomy.taxeditor.store.CdmStore;
24

    
25
public class TaxonEditorInput extends AbstractBulkEditorInput<TaxonBase>{
26

    
27
	private static TaxonEditorInput instance;
28
	/** Constant <code>ID="bulkeditor.input.taxon"</code> */
29
	public static final String ID = "bulkeditor.input.taxon";
30

    
31

    
32

    
33
	/**
34
	 * <p>Getter for the field <code>instance</code>.</p>
35
	 *
36
	 * @return a {@link eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput} object.
37
	 */
38
	public static AbstractBulkEditorInput getInstance() {
39
		if (instance == null) {
40
			instance = new TaxonEditorInput();
41
		}
42

    
43
		return instance;
44
	}
45

    
46

    
47
	@Override
48
	public String getName() {
49
		return BulkEditorInputType.TAXON.label;
50
	}
51

    
52
	@Override
53
	public String getToolTipText() {
54
		return getName();
55
	}
56

    
57

    
58
	/**
59
	 * <p>getID</p>
60
	 *
61
	 * @return a {@link java.lang.Object} object.
62
	 */
63
	public static Object getID() {
64
		return ID;
65
	}
66

    
67
	/* (non-Javadoc)
68
	 * @see eu.etaxonomy.taxeditor.bulkeditor.input.BulkEditorInput#isMergingEnabled()
69
	 */
70
	/** {@inheritDoc} */
71
	@Override
72
	public boolean isMergingEnabled() {
73
		return false;
74
	}
75
	@Override
76
	public TaxonBase save(TaxonBase entity) {
77
	    return CdmStore.getService(ITaxonService.class).merge(entity, true).getMergedEntity();
78
	}
79

    
80

    
81

    
82
	/** {@inheritDoc} */
83
	@Override
84
	public List listEntities(IIdentifiableEntityServiceConfigurator configurator) {
85
//		IFindTaxaAndNamesConfigurator<TaxonBase> newConfig = new FindTaxaAndNamesConfiguratorImpl<TaxonBase>();
86
//		newConfig.setTitleSearchString(configurator.getTitleSearchStringSqlized());
87
//		newConfig.setMatchMode(MatchMode.ANYWHERE);
88
		
89
		List<TaxonBase> taxa =  CdmStore.getSearchManager().findTaxa(configurator);
90
		List<TaxonBase> taxaCopy = new ArrayList<TaxonBase>();
91
		for (TaxonBase taxon:taxa){
92

    
93
			if (taxon instanceof Taxon){
94
				taxaCopy.add(HibernateProxyHelper.deproxy(taxon, Taxon.class));
95
			}else{
96
				taxaCopy.add(HibernateProxyHelper.deproxy(taxon, Synonym.class));
97
			}
98
		}
99
		return taxaCopy;
100
	}
101

    
102

    
103
	@Override
104
	protected TaxonBase loadEntity(UUID entityUuid) {
105
		List<String> propertyPaths = Arrays.asList(new String[]{});
106
		return CdmStore.getService(ITaxonService.class).load(entityUuid, propertyPaths);
107
	}
108

    
109

    
110

    
111
	/** {@inheritDoc}
112
	 * @throws ReferencedObjectUndeletableException */
113
	@Override
114
    public boolean delete(TaxonBase entity, DeleteConfiguratorBase config) {
115
		if (entity instanceof Taxon){
116
			TaxonDeletionConfigurator taxonConfig = null;
117
			if (config instanceof TaxonDeletionConfigurator){
118
				taxonConfig = (TaxonDeletionConfigurator)config;
119
			}else{
120
				
121
			}
122
			
123
			return CdmStore.getService(ITaxonService.class).deleteTaxon(entity.getUuid(), taxonConfig, null) != null;
124
		} else{
125
			SynonymDeletionConfigurator synConfig = null;
126
			if (config instanceof SynonymDeletionConfigurator){
127
				synConfig = (SynonymDeletionConfigurator)config;
128
			}else{
129
				
130
			}
131
			
132
			return CdmStore.getService(ITaxonService.class).deleteSynonym(entity.getUuid(), synConfig) != null;
133
		}
134
	}
135
	@Override
136
	protected IEntityCreator<TaxonBase> createEntityCreator() {
137
		return new TaxonCreator();
138
	}
139

    
140

    
141
    /* (non-Javadoc)
142
     * @see eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput#merge()
143
     */
144
    @Override
145
    public void merge() {
146

    
147
    }
148

    
149
}
(10-10/11)