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