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 static final String PROPERTY_PUBLISH = "Publish";
|
33
|
|
34
|
private List<TaxonName> saveNameCandidates = new ArrayList<>();
|
35
|
|
36
|
public static AbstractBulkEditorInput getInstance() {
|
37
|
if (instance == null) {
|
38
|
instance = new TaxonEditorInput();
|
39
|
}
|
40
|
|
41
|
return instance;
|
42
|
}
|
43
|
|
44
|
@Override
|
45
|
protected List<String> getPropertyKeys_internal() {
|
46
|
List<String> propertyKeysInternal = new ArrayList<>();
|
47
|
propertyKeysInternal.add(PROPERTY_PUBLISH);
|
48
|
return propertyKeysInternal;
|
49
|
}
|
50
|
|
51
|
@Override
|
52
|
public Object getPropertyValue(TaxonBase cdmBase, String property) {
|
53
|
if(property.equals(PROPERTY_PUBLISH)){
|
54
|
return cdmBase.isPublish();
|
55
|
}
|
56
|
return super.getPropertyValue(cdmBase, property);
|
57
|
}
|
58
|
|
59
|
@Override
|
60
|
public boolean isBooleanProperty(String property) {
|
61
|
if(property.equals(PROPERTY_PUBLISH)){
|
62
|
return true;
|
63
|
}
|
64
|
return super.isBooleanProperty(property);
|
65
|
}
|
66
|
|
67
|
@Override
|
68
|
public String getName() {
|
69
|
return BulkEditorInputType.TAXON.label;
|
70
|
}
|
71
|
|
72
|
public static Object getID() {
|
73
|
return ID;
|
74
|
}
|
75
|
|
76
|
@Override
|
77
|
public List<IBulkEditorSortProvider<TaxonBase>> getSortProviders() {
|
78
|
List<IBulkEditorSortProvider<TaxonBase>> sortProviders = super.getSortProviders();
|
79
|
|
80
|
sortProviders.add(0, new IdentifiableEntitySortProvider<TaxonBase>());
|
81
|
|
82
|
return sortProviders;
|
83
|
}
|
84
|
|
85
|
@Override
|
86
|
public boolean isMergingEnabled() {
|
87
|
return false;
|
88
|
}
|
89
|
@Override
|
90
|
public TaxonBase save(TaxonBase entity) {
|
91
|
return CdmStore.getService(ITaxonService.class).merge(entity, true).getMergedEntity();
|
92
|
}
|
93
|
|
94
|
@Override
|
95
|
protected long countEntities(IIdentifiableEntityServiceConfigurator configurator) {
|
96
|
return CdmStore.getService(ITaxonService.class).countByTitle(configurator);
|
97
|
}
|
98
|
|
99
|
@Override
|
100
|
public List listEntities(IIdentifiableEntityServiceConfigurator configurator) {
|
101
|
// IFindTaxaAndNamesConfigurator<TaxonBase> newConfig = new FindTaxaAndNamesConfiguratorImpl<>();
|
102
|
// newConfig.setTitleSearchString(configurator.getTitleSearchStringSqlized());
|
103
|
// newConfig.setMatchMode(MatchMode.ANYWHERE);
|
104
|
|
105
|
List<TaxonBase> taxa = CdmStore.getSearchManager().findTaxa(configurator);
|
106
|
List<TaxonBase> taxaCopy = new ArrayList<TaxonBase>();
|
107
|
for (TaxonBase taxon:taxa){
|
108
|
|
109
|
if (taxon instanceof Taxon){
|
110
|
taxaCopy.add(HibernateProxyHelper.deproxy(taxon, Taxon.class));
|
111
|
}else{
|
112
|
taxaCopy.add(HibernateProxyHelper.deproxy(taxon, Synonym.class));
|
113
|
}
|
114
|
}
|
115
|
return taxaCopy;
|
116
|
}
|
117
|
|
118
|
@Override
|
119
|
protected TaxonBase loadEntity(UUID entityUuid) {
|
120
|
List<String> propertyPaths = Arrays.asList(new String[]{});
|
121
|
return CdmStore.getService(ITaxonService.class).load(entityUuid, propertyPaths);
|
122
|
}
|
123
|
|
124
|
@Override
|
125
|
public boolean delete(TaxonBase entity, DeleteConfiguratorBase config) {
|
126
|
if (entity instanceof Taxon){
|
127
|
TaxonDeletionConfigurator taxonConfig = null;
|
128
|
if (config instanceof TaxonDeletionConfigurator){
|
129
|
taxonConfig = (TaxonDeletionConfigurator)config;
|
130
|
}else{
|
131
|
|
132
|
}
|
133
|
|
134
|
return CdmStore.getService(ITaxonService.class).deleteTaxon(entity.getUuid(), taxonConfig, null) != null;
|
135
|
} else{
|
136
|
SynonymDeletionConfigurator synConfig = null;
|
137
|
if (config instanceof SynonymDeletionConfigurator){
|
138
|
synConfig = (SynonymDeletionConfigurator)config;
|
139
|
}else{
|
140
|
|
141
|
}
|
142
|
|
143
|
return CdmStore.getService(ITaxonService.class).deleteSynonym(entity.getUuid(), synConfig) != null;
|
144
|
}
|
145
|
}
|
146
|
|
147
|
@Override
|
148
|
protected IEntityCreator<TaxonBase> createEntityCreator() {
|
149
|
return new TaxonCreator();
|
150
|
}
|
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
|
}
|