Project

General

Profile

Download (3.57 KB) Statistics
| Branch: | Tag: | Revision:
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.ITaxonService;
9
import eu.etaxonomy.cdm.api.service.config.FindTaxaAndNamesConfiguratorImpl;
10
import eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator;
11
import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
12
import eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException;
13
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
14
import eu.etaxonomy.cdm.model.taxon.Synonym;
15
import eu.etaxonomy.cdm.model.taxon.Taxon;
16
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
17
import eu.etaxonomy.cdm.persistence.query.MatchMode;
18
import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator;
19
import eu.etaxonomy.taxeditor.bulkeditor.input.entitycreator.TaxonCreator;
20
import eu.etaxonomy.taxeditor.store.CdmStore;
21

    
22
public class TaxonEditorInput extends AbstractBulkEditorInput<TaxonBase>{
23

    
24
	private static TaxonEditorInput instance;
25
	/** Constant <code>ID="bulkeditor.input.taxon"</code> */
26
	public static final String ID = "bulkeditor.input.taxon";
27

    
28

    
29

    
30
	/**
31
	 * <p>Getter for the field <code>instance</code>.</p>
32
	 *
33
	 * @return a {@link eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput} object.
34
	 */
35
	public static AbstractBulkEditorInput getInstance() {
36
		if (instance == null) {
37
			instance = new TaxonEditorInput();
38
		}
39

    
40
		return instance;
41
	}
42

    
43

    
44
	@Override
45
	public String getName() {
46
		return BulkEditorInputType.TAXON.label;
47
	}
48

    
49
	@Override
50
	public String getToolTipText() {
51
		return getName();
52
	}
53

    
54

    
55
	/**
56
	 * <p>getID</p>
57
	 *
58
	 * @return a {@link java.lang.Object} object.
59
	 */
60
	public static Object getID() {
61
		return ID;
62
	}
63

    
64
	/* (non-Javadoc)
65
	 * @see eu.etaxonomy.taxeditor.bulkeditor.input.BulkEditorInput#isMergingEnabled()
66
	 */
67
	/** {@inheritDoc} */
68
	@Override
69
	public boolean isMergingEnabled() {
70
		return false;
71
	}
72
	@Override
73
	public TaxonBase save(TaxonBase entity) {
74
	    return CdmStore.getService(ITaxonService.class).merge(entity, true).getMergedEntity();
75
	}
76

    
77

    
78

    
79
	/** {@inheritDoc} */
80
	@Override
81
	public List listEntities(IIdentifiableEntityServiceConfigurator configurator) {
82
		IFindTaxaAndNamesConfigurator<TaxonBase> newConfig = new FindTaxaAndNamesConfiguratorImpl<TaxonBase>();
83
		newConfig.setTitleSearchString(configurator.getTitleSearchStringSqlized());
84
		newConfig.setMatchMode(MatchMode.ANYWHERE);
85
		List<TaxonBase> taxa =  CdmStore.getSearchManager().findTaxa(configurator);
86
		List<TaxonBase> taxaCopy = new ArrayList<TaxonBase>();
87
		for (TaxonBase taxon:taxa){
88

    
89
			if (taxon instanceof Taxon){
90
				taxaCopy.add(HibernateProxyHelper.deproxy(taxon, Taxon.class));
91
			}else{
92
				taxaCopy.add(HibernateProxyHelper.deproxy(taxon, Synonym.class));
93
			}
94
		}
95
		return taxaCopy;
96
	}
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

    
106

    
107
	/** {@inheritDoc}
108
	 * @throws ReferencedObjectUndeletableException */
109
	@Override
110
    public boolean delete(TaxonBase entity) {
111
		return CdmStore.getService(ITaxonService.class).delete(entity) != null;
112
	}
113
	@Override
114
	protected IEntityCreator<TaxonBase> createEntityCreator() {
115
		return new TaxonCreator();
116
	}
117

    
118

    
119
    /* (non-Javadoc)
120
     * @see eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput#merge()
121
     */
122
    @Override
123
    public void merge() {
124

    
125
    }
126

    
127
}
(11-11/12)