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.FindTaxaAndNamesConfiguratorImpl;
|
10
|
import eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator;
|
11
|
import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
|
12
|
import eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException;
|
13
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
14
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
15
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
16
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
17
|
import eu.etaxonomy.cdm.persistence.query.MatchMode;
|
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
|
|
44
|
@Override
|
45
|
public String getName() {
|
46
|
return BulkEditorInputType.TAXON.label;
|
47
|
}
|
48
|
|
49
|
@Override
|
50
|
public String getToolTipText() {
|
51
|
return getName();
|
52
|
}
|
53
|
|
54
|
|
55
|
/**
|
56
|
* <p>getID</p>
|
57
|
*
|
58
|
* @return a {@link java.lang.Object} object.
|
59
|
*/
|
60
|
public static Object getID() {
|
61
|
return ID;
|
62
|
}
|
63
|
|
64
|
/* (non-Javadoc)
|
65
|
* @see eu.etaxonomy.taxeditor.bulkeditor.input.BulkEditorInput#isMergingEnabled()
|
66
|
*/
|
67
|
/** {@inheritDoc} */
|
68
|
@Override
|
69
|
public boolean isMergingEnabled() {
|
70
|
return false;
|
71
|
}
|
72
|
@Override
|
73
|
public boolean save(TaxonBase entity) {
|
74
|
if(CdmStore.getCurrentSessionManager().isRemoting()) {
|
75
|
return CdmStore.getService(ITaxonService.class).merge(entity) != null;
|
76
|
} else {
|
77
|
return CdmStore.getService(ITaxonService.class).saveOrUpdate(entity) != null;
|
78
|
}
|
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
|
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) {
|
115
|
return CdmStore.getService(ITaxonService.class).delete(entity) != null;
|
116
|
}
|
117
|
@Override
|
118
|
protected IEntityCreator<TaxonBase> createEntityCreator() {
|
119
|
return new TaxonCreator();
|
120
|
}
|
121
|
|
122
|
|
123
|
/* (non-Javadoc)
|
124
|
* @see eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput#merge()
|
125
|
*/
|
126
|
@Override
|
127
|
public void merge() {
|
128
|
|
129
|
}
|
130
|
|
131
|
}
|