Project

General

Profile

Download (4.69 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

    
10
package eu.etaxonomy.taxeditor.bulkeditor.input;
11

    
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.config.DeleteConfiguratorBase;
18
import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
19
import eu.etaxonomy.cdm.api.service.config.NameDeletionConfigurator;
20
import eu.etaxonomy.cdm.model.name.TaxonName;
21
import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator;
22
import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorSortProvider;
23
import eu.etaxonomy.taxeditor.bulkeditor.input.entitycreator.NameCreator;
24
import eu.etaxonomy.taxeditor.bulkeditor.input.sortprovider.IdentifiableEntitySortProvider;
25
import eu.etaxonomy.taxeditor.store.CdmStore;
26

    
27
/**
28
 * <p>NameEditorInput class.</p>
29
 *
30
 * @author p.ciardelli
31
 * @created 20.08.2009
32
 */
33
public class NameEditorInput extends AbstractBulkEditorInput<TaxonName> {
34

    
35
	private static final long serialVersionUID = -3085029575759626823L;
36
	private static NameEditorInput instance;
37

    
38
	/** Constant <code>ID="bulkeditor.input.name"</code> */
39
	public static final String ID = "bulkeditor.input.name";
40

    
41
	/**
42
	 * <p>Getter for the field <code>instance</code>.</p>
43
	 *
44
	 * @return a {@link eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput} object.
45
	 */
46
	public static AbstractBulkEditorInput getInstance() {
47
		if (instance == null) {
48
			instance = new NameEditorInput();
49
		}
50
		return instance;
51
	}
52

    
53
    @Override
54
    public String getName() {
55
		return BulkEditorInputType.NAME.label;
56
	}
57

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

    
67
	/* (non-Javadoc)
68
	 * @see eu.etaxonomy.taxeditor.bulkeditor.input.BulkEditorInput#isMergingEnabled()
69
	 */
70
	/** {@inheritDoc} */
71
	@Override
72
	public boolean isMergingEnabled() {
73
		return false;
74
	}
75

    
76
	/** {@inheritDoc} */
77
	@Override
78
	public List listEntities(IIdentifiableEntityServiceConfigurator configurator) {
79

    
80
		configurator.setPropertyPaths(getPropertyPaths());
81
		return CdmStore.getSearchManager().findNames(configurator, this.getConversation());
82
	}
83

    
84
	/** {@inheritDoc}
85
	@Override
86
	public TaxonNameBase loadEntity(UUID uuid) {
87
		List<String> propertyPaths = Arrays.asList(new String[]{});
88
		return CdmStore.getService(INameService.class).load(uuid, propertyPaths);
89
	}
90
*/
91
	@Override
92
    public boolean delete(TaxonName entity, DeleteConfiguratorBase config)  {
93
		NameDeletionConfigurator nameConfig = null;
94
		if (config instanceof NameDeletionConfigurator){
95
			nameConfig = (NameDeletionConfigurator) config;
96
		} else{
97

    
98
		}
99
		return CdmStore.getService(INameService.class).delete(entity.getUuid(), nameConfig) != null;
100
	}
101

    
102
	/** {@inheritDoc} */
103
	@Override
104
    public TaxonName save(TaxonName entity) {
105
		TaxonName mergedName = null;
106
		mergedName =  CdmStore.getService(INameService.class).merge(entity, true).getMergedEntity();
107
	   	return mergedName;
108

    
109
	}
110

    
111
	@Override
112
	protected IEntityCreator<TaxonName> createEntityCreator() {
113
		return new NameCreator();
114
	}
115

    
116
	@Override
117
	public List<IBulkEditorSortProvider<TaxonName>> getSortProviders() {
118
		List<IBulkEditorSortProvider<TaxonName>> sortProviders = super.getSortProviders();
119

    
120
		sortProviders.add(0, new IdentifiableEntitySortProvider<>());
121

    
122
		return sortProviders;
123
	}
124

    
125
	@Override
126
	public String getTypeText(Object entity) {
127
		if((entity instanceof TaxonName) && (((TaxonName) entity).getNomenclaturalCode() != null)){
128
			return ((TaxonName) entity).getNomenclaturalCode().getTitleCache();
129
		}
130
		return super.getTypeText(entity);
131
	}
132

    
133
	@Override
134
	public String getText(TaxonName entity) {
135
		return (entity).getFullTitleCache();
136
	}
137

    
138
    @Override
139
    public void merge() {
140

    
141
    }
142

    
143
	@Override
144
	protected TaxonName loadEntity(UUID entityUuid) {
145
		List<String> propertyPaths = Arrays.asList(new String[]{});
146
		return CdmStore.getService(INameService.class).load(entityUuid, getPropertyPaths());
147
	}
148

    
149

    
150
    private List<String> getPropertyPaths(){
151
    	 List<String> nameBasePropertyPaths = Arrays.asList(new String[] {
152
    	 "name.descriptions",
153
         "name.typeDesignations",
154
         "name.status",
155
         "name.nomenclaturalReference.inReference",
156
         "name.taxonBases.taxonNodes",
157
         "name.relationsFromThisName",
158
         "name.relationsToThisName",
159
         "name.homotypicalGroup.typifiedNames.taxonBases.synonymRelations.synonym.name.status",
160
         "name.homotypicalGroup.typifiedNames.relationsToThisName.fromName"});
161

    
162
    	 return nameBasePropertyPaths;
163
    }
164

    
165
}
(6-6/11)