Project

General

Profile

Download (4.07 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.IIdentifiableEntityServiceConfigurator;
11
import eu.etaxonomy.cdm.api.service.config.SynonymDeletionConfigurator;
12
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
13
import eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException;
14
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
15
import eu.etaxonomy.cdm.model.taxon.Synonym;
16
import eu.etaxonomy.cdm.model.taxon.Taxon;
17
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
18
import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator;
19
import eu.etaxonomy.taxeditor.bulkeditor.input.entitycreator.TaxonCreator;
20
import eu.etaxonomy.taxeditor.store.CdmStore;
21

    
22
public class TaxonEditorInput extends AbstractBulkEditorInput<TaxonBase>{
23

    
24
	private static TaxonEditorInput instance;
25
	/** Constant <code>ID="bulkeditor.input.taxon"</code> */
26
	public static final String ID = "bulkeditor.input.taxon";
27

    
28

    
29

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

    
40
		return instance;
41
	}
42

    
43
    @Override
44
	public String getName() {
45
		return BulkEditorInputType.TAXON.label;
46
	}
47

    
48
	/**
49
	 * <p>getID</p>
50
	 *
51
	 * @return a {@link java.lang.Object} object.
52
	 */
53
	public static Object getID() {
54
		return ID;
55
	}
56

    
57
	/* (non-Javadoc)
58
	 * @see eu.etaxonomy.taxeditor.bulkeditor.input.BulkEditorInput#isMergingEnabled()
59
	 */
60
	/** {@inheritDoc} */
61
	@Override
62
	public boolean isMergingEnabled() {
63
		return false;
64
	}
65
	@Override
66
	public TaxonBase save(TaxonBase entity) {
67
	    return CdmStore.getService(ITaxonService.class).merge(entity, true).getMergedEntity();
68
	}
69

    
70

    
71

    
72
	/** {@inheritDoc} */
73
	@Override
74
	public List listEntities(IIdentifiableEntityServiceConfigurator configurator) {
75
//		IFindTaxaAndNamesConfigurator<TaxonBase> newConfig = new FindTaxaAndNamesConfiguratorImpl<TaxonBase>();
76
//		newConfig.setTitleSearchString(configurator.getTitleSearchStringSqlized());
77
//		newConfig.setMatchMode(MatchMode.ANYWHERE);
78

    
79
		List<TaxonBase> taxa =  CdmStore.getSearchManager().findTaxa(configurator);
80
		List<TaxonBase> taxaCopy = new ArrayList<TaxonBase>();
81
		for (TaxonBase taxon:taxa){
82

    
83
			if (taxon instanceof Taxon){
84
				taxaCopy.add(HibernateProxyHelper.deproxy(taxon, Taxon.class));
85
			}else{
86
				taxaCopy.add(HibernateProxyHelper.deproxy(taxon, Synonym.class));
87
			}
88
		}
89
		return taxaCopy;
90
	}
91

    
92

    
93
	@Override
94
	protected TaxonBase loadEntity(UUID entityUuid) {
95
		List<String> propertyPaths = Arrays.asList(new String[]{});
96
		return CdmStore.getService(ITaxonService.class).load(entityUuid, propertyPaths);
97
	}
98

    
99

    
100

    
101
	/** {@inheritDoc}
102
	 * @throws ReferencedObjectUndeletableException */
103
	@Override
104
    public boolean delete(TaxonBase entity, DeleteConfiguratorBase config) {
105
		if (entity instanceof Taxon){
106
			TaxonDeletionConfigurator taxonConfig = null;
107
			if (config instanceof TaxonDeletionConfigurator){
108
				taxonConfig = (TaxonDeletionConfigurator)config;
109
			}else{
110

    
111
			}
112

    
113
			return CdmStore.getService(ITaxonService.class).deleteTaxon(entity.getUuid(), taxonConfig, null) != null;
114
		} else{
115
			SynonymDeletionConfigurator synConfig = null;
116
			if (config instanceof SynonymDeletionConfigurator){
117
				synConfig = (SynonymDeletionConfigurator)config;
118
			}else{
119

    
120
			}
121

    
122
			return CdmStore.getService(ITaxonService.class).deleteSynonym(entity.getUuid(), synConfig) != null;
123
		}
124
	}
125
	@Override
126
	protected IEntityCreator<TaxonBase> createEntityCreator() {
127
		return new TaxonCreator();
128
	}
129

    
130

    
131
    /* (non-Javadoc)
132
     * @see eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput#merge()
133
     */
134
    @Override
135
    public void merge() {
136

    
137
    }
138

    
139
}
(10-10/11)