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.IBulkEditorSortProvider;
|
20
|
import eu.etaxonomy.taxeditor.bulkeditor.input.entitycreator.TaxonCreator;
|
21
|
import eu.etaxonomy.taxeditor.bulkeditor.input.sortprovider.IdentifiableEntitySortProvider;
|
22
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
23
|
|
24
|
public class TaxonEditorInput extends AbstractBulkEditorInput<TaxonBase>{
|
25
|
|
26
|
private static TaxonEditorInput instance;
|
27
|
/** Constant <code>ID="bulkeditor.input.taxon"</code> */
|
28
|
public static final String ID = "bulkeditor.input.taxon";
|
29
|
|
30
|
|
31
|
|
32
|
/**
|
33
|
* <p>Getter for the field <code>instance</code>.</p>
|
34
|
*
|
35
|
* @return a {@link eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput} object.
|
36
|
*/
|
37
|
public static AbstractBulkEditorInput getInstance() {
|
38
|
if (instance == null) {
|
39
|
instance = new TaxonEditorInput();
|
40
|
}
|
41
|
|
42
|
return instance;
|
43
|
}
|
44
|
|
45
|
@Override
|
46
|
public String getName() {
|
47
|
return BulkEditorInputType.TAXON.label;
|
48
|
}
|
49
|
|
50
|
/**
|
51
|
* <p>getID</p>
|
52
|
*
|
53
|
* @return a {@link java.lang.Object} object.
|
54
|
*/
|
55
|
public static Object getID() {
|
56
|
return ID;
|
57
|
}
|
58
|
|
59
|
@Override
|
60
|
public List<IBulkEditorSortProvider<TaxonBase>> getSortProviders() {
|
61
|
List<IBulkEditorSortProvider<TaxonBase>> sortProviders = super.getSortProviders();
|
62
|
|
63
|
sortProviders.add(0, new IdentifiableEntitySortProvider<TaxonBase>());
|
64
|
|
65
|
return sortProviders;
|
66
|
}
|
67
|
|
68
|
/* (non-Javadoc)
|
69
|
* @see eu.etaxonomy.taxeditor.bulkeditor.input.BulkEditorInput#isMergingEnabled()
|
70
|
*/
|
71
|
/** {@inheritDoc} */
|
72
|
@Override
|
73
|
public boolean isMergingEnabled() {
|
74
|
return false;
|
75
|
}
|
76
|
@Override
|
77
|
public TaxonBase save(TaxonBase entity) {
|
78
|
return CdmStore.getService(ITaxonService.class).merge(entity, true).getMergedEntity();
|
79
|
}
|
80
|
|
81
|
|
82
|
|
83
|
/** {@inheritDoc} */
|
84
|
@Override
|
85
|
public List listEntities(IIdentifiableEntityServiceConfigurator configurator) {
|
86
|
// IFindTaxaAndNamesConfigurator<TaxonBase> newConfig = new FindTaxaAndNamesConfiguratorImpl<TaxonBase>();
|
87
|
// newConfig.setTitleSearchString(configurator.getTitleSearchStringSqlized());
|
88
|
// newConfig.setMatchMode(MatchMode.ANYWHERE);
|
89
|
|
90
|
List<TaxonBase> taxa = CdmStore.getSearchManager().findTaxa(configurator);
|
91
|
List<TaxonBase> taxaCopy = new ArrayList<TaxonBase>();
|
92
|
for (TaxonBase taxon:taxa){
|
93
|
|
94
|
if (taxon instanceof Taxon){
|
95
|
taxaCopy.add(HibernateProxyHelper.deproxy(taxon, Taxon.class));
|
96
|
}else{
|
97
|
taxaCopy.add(HibernateProxyHelper.deproxy(taxon, Synonym.class));
|
98
|
}
|
99
|
}
|
100
|
return taxaCopy;
|
101
|
}
|
102
|
|
103
|
|
104
|
@Override
|
105
|
protected TaxonBase loadEntity(UUID entityUuid) {
|
106
|
List<String> propertyPaths = Arrays.asList(new String[]{});
|
107
|
return CdmStore.getService(ITaxonService.class).load(entityUuid, propertyPaths);
|
108
|
}
|
109
|
|
110
|
|
111
|
|
112
|
/** {@inheritDoc}
|
113
|
* @throws ReferencedObjectUndeletableException */
|
114
|
@Override
|
115
|
public boolean delete(TaxonBase entity, DeleteConfiguratorBase config) {
|
116
|
if (entity instanceof Taxon){
|
117
|
TaxonDeletionConfigurator taxonConfig = null;
|
118
|
if (config instanceof TaxonDeletionConfigurator){
|
119
|
taxonConfig = (TaxonDeletionConfigurator)config;
|
120
|
}else{
|
121
|
|
122
|
}
|
123
|
|
124
|
return CdmStore.getService(ITaxonService.class).deleteTaxon(entity.getUuid(), taxonConfig, null) != null;
|
125
|
} else{
|
126
|
SynonymDeletionConfigurator synConfig = null;
|
127
|
if (config instanceof SynonymDeletionConfigurator){
|
128
|
synConfig = (SynonymDeletionConfigurator)config;
|
129
|
}else{
|
130
|
|
131
|
}
|
132
|
|
133
|
return CdmStore.getService(ITaxonService.class).deleteSynonym(entity.getUuid(), synConfig) != null;
|
134
|
}
|
135
|
}
|
136
|
@Override
|
137
|
protected IEntityCreator<TaxonBase> createEntityCreator() {
|
138
|
return new TaxonCreator();
|
139
|
}
|
140
|
|
141
|
|
142
|
/* (non-Javadoc)
|
143
|
* @see eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput#merge()
|
144
|
*/
|
145
|
@Override
|
146
|
public void merge() {
|
147
|
|
148
|
}
|
149
|
|
150
|
}
|