Project

General

Profile

Download (6.35 KB) Statistics
| Branch: | Tag: | Revision:
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.store.CdmStore;
33

    
34
public class TaxonEditorInput extends AbstractBulkEditorInput<TaxonBase>{
35

    
36
	private static TaxonEditorInput instance;
37

    
38
	public static final String ID = "bulkeditor.input.taxon";
39

    
40
	private static final String PROPERTY_PUBLISH = "Publish";
41

    
42
	private List<TaxonName> saveNameCandidates = new ArrayList<>();
43

    
44
	public static AbstractBulkEditorInput getInstance() {
45
		if (instance == null) {
46
			instance = new TaxonEditorInput();
47
		}
48

    
49
		return instance;
50
	}
51

    
52
    @Override
53
    protected List<String> getPropertyKeys_internal() {
54
        List<String> propertyKeysInternal = new ArrayList<>();
55
        propertyKeysInternal.add(PROPERTY_PUBLISH);
56
        return propertyKeysInternal;
57
    }
58

    
59
    @Override
60
    public Object getPropertyValue(TaxonBase cdmBase, String property) {
61
        if(property.equals(PROPERTY_PUBLISH)){
62
            return cdmBase.isPublish();
63
        }
64
        return super.getPropertyValue(cdmBase, property);
65
    }
66

    
67
    @Override
68
    public boolean isBooleanProperty(String property) {
69
        if(property.equals(PROPERTY_PUBLISH)){
70
            return true;
71
        }
72
        return super.isBooleanProperty(property);
73
    }
74

    
75
    @Override
76
	public String getName() {
77
		return BulkEditorInputType.TAXON.label;
78
	}
79

    
80
	public static Object getID() {
81
		return ID;
82
	}
83

    
84
	@Override
85
    public List<IBulkEditorSortProvider<TaxonBase>> getSortProviders() {
86
        List<IBulkEditorSortProvider<TaxonBase>> sortProviders = super.getSortProviders();
87

    
88
        sortProviders.add(0, new IdentifiableEntitySortProvider<TaxonBase>());
89

    
90
        return sortProviders;
91
    }
92

    
93
	@Override
94
	public boolean isMergingEnabled() {
95
		return false;
96
	}
97
	@Override
98
	public TaxonBase save(TaxonBase entity) {
99
	    return CdmStore.getService(ITaxonService.class).merge(entity, true).getMergedEntity();
100
	}
101

    
102
    @Override
103
    protected long countEntities(IIdentifiableEntityServiceConfigurator configurator) {
104
        return CdmStore.getService(ITaxonService.class).countByTitle(configurator);
105
    }
106

    
107
	@Override
108
	public List listEntities(IIdentifiableEntityServiceConfigurator configurator) {
109
//		IFindTaxaAndNamesConfigurator<TaxonBase> newConfig = new FindTaxaAndNamesConfiguratorImpl<>();
110
//		newConfig.setTitleSearchString(configurator.getTitleSearchStringSqlized());
111
//		newConfig.setMatchMode(MatchMode.ANYWHERE);
112
	    List<String> propertyPaths = getPropertyPaths();
113
	    configurator.setPropertyPaths(propertyPaths);
114
		List<TaxonBase> taxa =  CdmStore.getSearchManager().findTaxa(configurator);
115
		List<TaxonBase> taxaCopy = new ArrayList<TaxonBase>();
116
		for (TaxonBase taxon:taxa){
117

    
118
			if (taxon instanceof Taxon){
119
				taxaCopy.add(HibernateProxyHelper.deproxy(taxon, Taxon.class));
120
			}else{
121
				taxaCopy.add(HibernateProxyHelper.deproxy(taxon, Synonym.class));
122
			}
123
		}
124
		return taxaCopy;
125
	}
126

    
127
	@Override
128
	protected TaxonBase loadEntity(UUID entityUuid) {
129
		List<String> propertyPaths = Arrays.asList(new String[]{});
130
		return CdmStore.getService(ITaxonService.class).load(entityUuid, propertyPaths);
131
	}
132

    
133
	@Override
134
    public boolean delete(TaxonBase entity, DeleteConfiguratorBase config) {
135
		if (entity instanceof Taxon){
136
			TaxonDeletionConfigurator taxonConfig = null;
137
			if (config instanceof TaxonDeletionConfigurator){
138
				taxonConfig = (TaxonDeletionConfigurator)config;
139
			}else{
140

    
141
			}
142

    
143
			return CdmStore.getService(ITaxonService.class).deleteTaxon(entity.getUuid(), taxonConfig, null) != null;
144
		} else{
145
			SynonymDeletionConfigurator synConfig = null;
146
			if (config instanceof SynonymDeletionConfigurator){
147
				synConfig = (SynonymDeletionConfigurator)config;
148
			}else{
149

    
150
			}
151

    
152
			return CdmStore.getService(ITaxonService.class).deleteSynonym(entity.getUuid(), synConfig) != null;
153
		}
154
	}
155

    
156
	@Override
157
	protected IEntityCreator<TaxonBase> createEntityCreator() {
158
		return new TaxonCreator();
159
	}
160

    
161
    @Override
162
    public void merge() {
163

    
164
    }
165

    
166
    @Override
167
    public void addSaveCandidate(TaxonBase taxonBase){
168
        if (!taxonBase.getName().getHybridChildRelations().isEmpty()){
169
            for (HybridRelationship rel: taxonBase.getName().getHybridChildRelations()){
170
                if (!rel.getParentName().isPersited()){
171
                    this.saveNameCandidates.add(rel.getParentName());
172
                }
173
                if (!rel.getHybridName().isPersited()){
174
                    this.saveNameCandidates.add(rel.getHybridName());
175
                }
176
            }
177
        }
178

    
179
        super.addSaveCandidate(taxonBase);
180
    }
181

    
182
    @Override
183
    public void saveModel(boolean resetMerge){
184
        CdmStore.getService(INameService.class).save(this.saveNameCandidates);
185
        super.saveModel(resetMerge);
186
    }
187

    
188
    private List<String> getPropertyPaths(){
189
        List<String> taxonBasePropertyPaths = Arrays.asList(new String[] {
190
        "descriptions.descriptionElements.*",
191
        "typeDesignations"});
192

    
193
        return taxonBasePropertyPaths;
194
   }
195

    
196
}
(10-10/11)