1 |
3f8e87ed
|
Katja Luther
|
package eu.etaxonomy.taxeditor.bulkeditor.input;
|
2 |
|
|
|
3 |
11329ecc
|
Katja Luther
|
import java.util.ArrayList;
|
4 |
3f8e87ed
|
Katja Luther
|
import java.util.Arrays;
|
5 |
|
|
import java.util.List;
|
6 |
|
|
import java.util.UUID;
|
7 |
|
|
|
8 |
baace0b5
|
Katja Luther
|
import eu.etaxonomy.cdm.api.service.INameService;
|
9 |
3f8e87ed
|
Katja Luther
|
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
10 |
fc545014
|
Katja Luther
|
import eu.etaxonomy.cdm.api.service.config.DeleteConfiguratorBase;
|
11 |
3f8e87ed
|
Katja Luther
|
import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
|
12 |
fc545014
|
Katja Luther
|
import eu.etaxonomy.cdm.api.service.config.SynonymDeletionConfigurator;
|
13 |
|
|
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
|
14 |
11329ecc
|
Katja Luther
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
15 |
baace0b5
|
Katja Luther
|
import eu.etaxonomy.cdm.model.name.HybridRelationship;
|
16 |
|
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
17 |
11329ecc
|
Katja Luther
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
18 |
|
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
19 |
3f8e87ed
|
Katja Luther
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
20 |
|
|
import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator;
|
21 |
ddd5d8cd
|
Katja Luther
|
import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorSortProvider;
|
22 |
3f8e87ed
|
Katja Luther
|
import eu.etaxonomy.taxeditor.bulkeditor.input.entitycreator.TaxonCreator;
|
23 |
ddd5d8cd
|
Katja Luther
|
import eu.etaxonomy.taxeditor.bulkeditor.input.sortprovider.IdentifiableEntitySortProvider;
|
24 |
3f8e87ed
|
Katja Luther
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
25 |
|
|
|
26 |
|
|
public class TaxonEditorInput extends AbstractBulkEditorInput<TaxonBase>{
|
27 |
|
|
|
28 |
|
|
private static TaxonEditorInput instance;
|
29 |
de3db973
|
Patrick Plitzner
|
|
30 |
3f8e87ed
|
Katja Luther
|
public static final String ID = "bulkeditor.input.taxon";
|
31 |
233a8fe2
|
Cherian Mathew
|
|
32 |
baace0b5
|
Katja Luther
|
private List<TaxonName> saveNameCandidates = new ArrayList<>();
|
33 |
233a8fe2
|
Cherian Mathew
|
|
34 |
3f8e87ed
|
Katja Luther
|
public static AbstractBulkEditorInput getInstance() {
|
35 |
|
|
if (instance == null) {
|
36 |
|
|
instance = new TaxonEditorInput();
|
37 |
|
|
}
|
38 |
233a8fe2
|
Cherian Mathew
|
|
39 |
3f8e87ed
|
Katja Luther
|
return instance;
|
40 |
|
|
}
|
41 |
233a8fe2
|
Cherian Mathew
|
|
42 |
521ddbfc
|
Patrick Plitzner
|
@Override
|
43 |
|
|
protected List<String> getPropertyKeys_internal() {
|
44 |
|
|
List<String> propertyKeysInternal = new ArrayList<>();
|
45 |
|
|
return propertyKeysInternal;
|
46 |
|
|
}
|
47 |
|
|
|
48 |
381bdda4
|
Patrick Plitzner
|
@Override
|
49 |
3f8e87ed
|
Katja Luther
|
public String getName() {
|
50 |
|
|
return BulkEditorInputType.TAXON.label;
|
51 |
|
|
}
|
52 |
|
|
|
53 |
|
|
public static Object getID() {
|
54 |
|
|
return ID;
|
55 |
|
|
}
|
56 |
233a8fe2
|
Cherian Mathew
|
|
57 |
ddd5d8cd
|
Katja Luther
|
@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 |
3f8e87ed
|
Katja Luther
|
@Override
|
67 |
|
|
public boolean isMergingEnabled() {
|
68 |
|
|
return false;
|
69 |
|
|
}
|
70 |
|
|
@Override
|
71 |
76fe3732
|
Cherian Mathew
|
public TaxonBase save(TaxonBase entity) {
|
72 |
d85cfdf3
|
Katja Luther
|
return CdmStore.getService(ITaxonService.class).merge(entity, true).getMergedEntity();
|
73 |
3f8e87ed
|
Katja Luther
|
}
|
74 |
|
|
|
75 |
fd28a17f
|
Patrick Plitzner
|
@Override
|
76 |
|
|
protected long countEntities(IIdentifiableEntityServiceConfigurator configurator) {
|
77 |
|
|
return CdmStore.getService(ITaxonService.class).countByTitle(configurator);
|
78 |
|
|
}
|
79 |
3f8e87ed
|
Katja Luther
|
|
80 |
|
|
@Override
|
81 |
|
|
public List listEntities(IIdentifiableEntityServiceConfigurator configurator) {
|
82 |
5235e093
|
Andreas Müller
|
// IFindTaxaAndNamesConfigurator<TaxonBase> newConfig = new FindTaxaAndNamesConfiguratorImpl<>();
|
83 |
fc545014
|
Katja Luther
|
// newConfig.setTitleSearchString(configurator.getTitleSearchStringSqlized());
|
84 |
|
|
// newConfig.setMatchMode(MatchMode.ANYWHERE);
|
85 |
381bdda4
|
Patrick Plitzner
|
|
86 |
11329ecc
|
Katja Luther
|
List<TaxonBase> taxa = CdmStore.getSearchManager().findTaxa(configurator);
|
87 |
|
|
List<TaxonBase> taxaCopy = new ArrayList<TaxonBase>();
|
88 |
|
|
for (TaxonBase taxon:taxa){
|
89 |
233a8fe2
|
Cherian Mathew
|
|
90 |
11329ecc
|
Katja Luther
|
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 |
3f8e87ed
|
Katja Luther
|
}
|
98 |
|
|
|
99 |
|
|
@Override
|
100 |
|
|
protected TaxonBase loadEntity(UUID entityUuid) {
|
101 |
233a8fe2
|
Cherian Mathew
|
List<String> propertyPaths = Arrays.asList(new String[]{});
|
102 |
3f8e87ed
|
Katja Luther
|
return CdmStore.getService(ITaxonService.class).load(entityUuid, propertyPaths);
|
103 |
|
|
}
|
104 |
|
|
|
105 |
233a8fe2
|
Cherian Mathew
|
@Override
|
106 |
fc545014
|
Katja Luther
|
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 |
381bdda4
|
Patrick Plitzner
|
|
113 |
fc545014
|
Katja Luther
|
}
|
114 |
381bdda4
|
Patrick Plitzner
|
|
115 |
fc545014
|
Katja Luther
|
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 |
381bdda4
|
Patrick Plitzner
|
|
122 |
fc545014
|
Katja Luther
|
}
|
123 |
381bdda4
|
Patrick Plitzner
|
|
124 |
fc545014
|
Katja Luther
|
return CdmStore.getService(ITaxonService.class).deleteSynonym(entity.getUuid(), synConfig) != null;
|
125 |
|
|
}
|
126 |
3f8e87ed
|
Katja Luther
|
}
|
127 |
de3db973
|
Patrick Plitzner
|
|
128 |
3f8e87ed
|
Katja Luther
|
@Override
|
129 |
|
|
protected IEntityCreator<TaxonBase> createEntityCreator() {
|
130 |
|
|
return new TaxonCreator();
|
131 |
|
|
}
|
132 |
|
|
|
133 |
8c8ead8a
|
Cherian Mathew
|
@Override
|
134 |
|
|
public void merge() {
|
135 |
|
|
|
136 |
|
|
}
|
137 |
|
|
|
138 |
baace0b5
|
Katja Luther
|
@Override
|
139 |
|
|
public void addSaveCandidate(TaxonBase taxonBase){
|
140 |
de3db973
|
Patrick Plitzner
|
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 |
baace0b5
|
Katja Luther
|
|
154 |
|
|
@Override
|
155 |
|
|
public void saveModel(boolean resetMerge){
|
156 |
|
|
CdmStore.getService(INameService.class).save(this.saveNameCandidates);
|
157 |
|
|
super.saveModel(resetMerge);
|
158 |
|
|
}
|
159 |
|
|
|
160 |
3f8e87ed
|
Katja Luther
|
}
|