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