Project

General

Profile

Download (3.73 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
	    if(CdmStore.getCurrentSessionManager().isRemoting()) {
75
	        return CdmStore.getService(ITaxonService.class).merge(entity, true);
76
	    } else {
77
	        CdmStore.getService(ITaxonService.class).saveOrUpdate(entity);
78
	        return entity;
79
	    }
80
	}
81

    
82

    
83

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

    
94
			if (taxon instanceof Taxon){
95
				taxaCopy.add(HibernateProxyHelper.deproxy(taxon, Taxon.class));
96
			}else{
97
				taxaCopy.add(HibernateProxyHelper.deproxy(taxon, Synonym.class));
98
			}
99
		}
100
		return taxaCopy;
101
	}
102

    
103

    
104
	@Override
105
	protected TaxonBase loadEntity(UUID entityUuid) {
106
		List<String> propertyPaths = Arrays.asList(new String[]{});
107
		return CdmStore.getService(ITaxonService.class).load(entityUuid, propertyPaths);
108
	}
109

    
110

    
111

    
112
	/** {@inheritDoc}
113
	 * @throws ReferencedObjectUndeletableException */
114
	@Override
115
    public boolean delete(TaxonBase entity) {
116
		return CdmStore.getService(ITaxonService.class).delete(entity) != null;
117
	}
118
	@Override
119
	protected IEntityCreator<TaxonBase> createEntityCreator() {
120
		return new TaxonCreator();
121
	}
122

    
123

    
124
    /* (non-Javadoc)
125
     * @see eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput#merge()
126
     */
127
    @Override
128
    public void merge() {
129

    
130
    }
131

    
132
}
(10-10/11)