1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.taxeditor.bulkeditor.input;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.Arrays;
|
13
|
import java.util.List;
|
14
|
import java.util.UUID;
|
15
|
|
16
|
import eu.etaxonomy.cdm.api.service.INameService;
|
17
|
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
18
|
import eu.etaxonomy.cdm.api.service.config.DeleteConfiguratorBase;
|
19
|
import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
|
20
|
import eu.etaxonomy.cdm.api.service.config.SynonymDeletionConfigurator;
|
21
|
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
|
22
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
23
|
import eu.etaxonomy.cdm.model.name.HybridRelationship;
|
24
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
25
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
26
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
27
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
28
|
import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator;
|
29
|
import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorSortProvider;
|
30
|
import eu.etaxonomy.taxeditor.bulkeditor.input.entitycreator.TaxonCreator;
|
31
|
import eu.etaxonomy.taxeditor.bulkeditor.input.sortprovider.IdentifiableEntitySortProvider;
|
32
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
33
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
34
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
35
|
|
36
|
public class TaxonEditorInput extends AbstractBulkEditorInput<TaxonBase>{
|
37
|
|
38
|
private static TaxonEditorInput instance;
|
39
|
|
40
|
public static final String ID = "bulkeditor.input.taxon";
|
41
|
|
42
|
private static final String PROPERTY_PUBLISH = "Publish";
|
43
|
|
44
|
private List<TaxonName> saveNameCandidates = new ArrayList<>();
|
45
|
|
46
|
public static AbstractBulkEditorInput getInstance() {
|
47
|
if (instance == null) {
|
48
|
instance = new TaxonEditorInput();
|
49
|
}
|
50
|
|
51
|
return instance;
|
52
|
}
|
53
|
|
54
|
@Override
|
55
|
protected List<String> getPropertyKeys_internal() {
|
56
|
List<String> propertyKeysInternal = new ArrayList<>();
|
57
|
propertyKeysInternal.add(PROPERTY_PUBLISH);
|
58
|
return propertyKeysInternal;
|
59
|
}
|
60
|
|
61
|
@Override
|
62
|
public Object getPropertyValue(TaxonBase cdmBase, String property) {
|
63
|
if(property.equals(PROPERTY_PUBLISH)){
|
64
|
return cdmBase.isPublish();
|
65
|
}
|
66
|
return super.getPropertyValue(cdmBase, property);
|
67
|
}
|
68
|
|
69
|
@Override
|
70
|
public boolean isBooleanProperty(String property) {
|
71
|
if(property.equals(PROPERTY_PUBLISH)){
|
72
|
return true;
|
73
|
}
|
74
|
return super.isBooleanProperty(property);
|
75
|
}
|
76
|
|
77
|
@Override
|
78
|
public String getName() {
|
79
|
return BulkEditorInputType.TAXON.label;
|
80
|
}
|
81
|
|
82
|
public static Object getID() {
|
83
|
return ID;
|
84
|
}
|
85
|
|
86
|
@Override
|
87
|
public List<IBulkEditorSortProvider<TaxonBase>> getSortProviders() {
|
88
|
List<IBulkEditorSortProvider<TaxonBase>> sortProviders = super.getSortProviders();
|
89
|
|
90
|
sortProviders.add(0, new IdentifiableEntitySortProvider<TaxonBase>());
|
91
|
|
92
|
return sortProviders;
|
93
|
}
|
94
|
|
95
|
@Override
|
96
|
public boolean isMergingEnabled() {
|
97
|
return false;
|
98
|
}
|
99
|
@Override
|
100
|
public TaxonBase save(TaxonBase entity) {
|
101
|
return CdmStore.getService(ITaxonService.class).merge(entity, true).getMergedEntity();
|
102
|
}
|
103
|
|
104
|
@Override
|
105
|
protected long countEntities(IIdentifiableEntityServiceConfigurator configurator) {
|
106
|
return CdmStore.getService(ITaxonService.class).countByTitle(configurator);
|
107
|
}
|
108
|
|
109
|
@Override
|
110
|
public List listEntities(IIdentifiableEntityServiceConfigurator configurator) {
|
111
|
// IFindTaxaAndNamesConfigurator<TaxonBase> newConfig = new FindTaxaAndNamesConfiguratorImpl<>();
|
112
|
// newConfig.setTitleSearchString(configurator.getTitleSearchStringSqlized());
|
113
|
// newConfig.setMatchMode(MatchMode.ANYWHERE);
|
114
|
List<String> propertyPaths = getPropertyPaths();
|
115
|
configurator.setPropertyPaths(propertyPaths);
|
116
|
List<TaxonBase> taxa = CdmStore.getSearchManager().findTaxa(configurator);
|
117
|
List<TaxonBase> taxaCopy = new ArrayList<TaxonBase>();
|
118
|
for (TaxonBase taxon:taxa){
|
119
|
|
120
|
if (taxon instanceof Taxon){
|
121
|
taxaCopy.add(HibernateProxyHelper.deproxy(taxon, Taxon.class));
|
122
|
}else{
|
123
|
taxaCopy.add(HibernateProxyHelper.deproxy(taxon, Synonym.class));
|
124
|
}
|
125
|
}
|
126
|
return taxaCopy;
|
127
|
}
|
128
|
|
129
|
@Override
|
130
|
protected TaxonBase loadEntity(UUID entityUuid) {
|
131
|
List<String> propertyPaths = Arrays.asList(new String[]{});
|
132
|
return CdmStore.getService(ITaxonService.class).load(entityUuid, propertyPaths);
|
133
|
}
|
134
|
|
135
|
@Override
|
136
|
public boolean delete(TaxonBase entity, DeleteConfiguratorBase config) {
|
137
|
if (entity instanceof Taxon){
|
138
|
TaxonDeletionConfigurator taxonConfig = null;
|
139
|
if (config instanceof TaxonDeletionConfigurator){
|
140
|
taxonConfig = (TaxonDeletionConfigurator)config;
|
141
|
}else{
|
142
|
|
143
|
}
|
144
|
|
145
|
return CdmStore.getService(ITaxonService.class).deleteTaxon(entity.getUuid(), taxonConfig, null) != null;
|
146
|
} else{
|
147
|
SynonymDeletionConfigurator synConfig = null;
|
148
|
if (config instanceof SynonymDeletionConfigurator){
|
149
|
synConfig = (SynonymDeletionConfigurator)config;
|
150
|
}else{
|
151
|
|
152
|
}
|
153
|
|
154
|
return CdmStore.getService(ITaxonService.class).deleteSynonym(entity.getUuid(), synConfig) != null;
|
155
|
}
|
156
|
}
|
157
|
|
158
|
@Override
|
159
|
protected IEntityCreator<TaxonBase> createEntityCreator() {
|
160
|
return new TaxonCreator();
|
161
|
}
|
162
|
|
163
|
@Override
|
164
|
public void merge() {
|
165
|
|
166
|
}
|
167
|
|
168
|
@Override
|
169
|
public void addSaveCandidate(TaxonBase taxonBase){
|
170
|
if (taxonBase == null){
|
171
|
MessagingUtils.info(Messages.TAXON_EDITOR_INPUT_Selection_lost);
|
172
|
return;
|
173
|
}
|
174
|
if (!taxonBase.getName().getHybridChildRelations().isEmpty()){
|
175
|
for (HybridRelationship rel: taxonBase.getName().getHybridChildRelations()){
|
176
|
if (!rel.getParentName().isPersited()){
|
177
|
this.saveNameCandidates.add(rel.getParentName());
|
178
|
}
|
179
|
if (!rel.getHybridName().isPersited()){
|
180
|
this.saveNameCandidates.add(rel.getHybridName());
|
181
|
}
|
182
|
}
|
183
|
}
|
184
|
|
185
|
super.addSaveCandidate(taxonBase);
|
186
|
}
|
187
|
|
188
|
@Override
|
189
|
public void saveModel(boolean resetMerge){
|
190
|
CdmStore.getService(INameService.class).save(this.saveNameCandidates);
|
191
|
super.saveModel(resetMerge);
|
192
|
}
|
193
|
|
194
|
private List<String> getPropertyPaths(){
|
195
|
List<String> taxonBasePropertyPaths = Arrays.asList(new String[] {
|
196
|
"descriptions.descriptionElements.*",
|
197
|
"typeDesignations"});
|
198
|
|
199
|
return taxonBasePropertyPaths;
|
200
|
}
|
201
|
}
|