Project

General

Profile

Revision 2f72f4da

ID2f72f4dab44df0d1ed4e4658b34e6f68e58b8156
Parent eb9880a0
Child d9fa828c

Added by Andreas Müller 12 months ago

ref #6794 add TermNodeService and TermTreeService and make FeatureXXX services deprecated

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/pilotOutputHtml/PilotOutputDescriptionExporter.java
32 32
import eu.etaxonomy.cdm.model.taxon.Taxon;
33 33
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
34 34
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
35
import eu.etaxonomy.cdm.model.term.TermType;
35 36

  
36 37
/**
37 38
 * @author h.fradin (from a.babadshanjan)
......
243 244
		if (sddExpConfig.isDoFeatureData() == true) {
244 245
			if (featureDataRows == 0) { featureDataRows = MAX_ROWS; }
245 246
			logger.info("# Feature Tree, Feature Node");
246
			sddDataSet.setFeatureData(getFeatureTreeService().getFeatureNodesAll());
247
			sddDataSet.setFeatureData(getTermNodeService().list(TermType.Feature,null,null,null,null));
247 248
			sddDataSet.addFeatureData(getFeatureTreeService().list(null,null,null,null,null));
248 249
		}
249 250
	}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/pilotOutputHtml/PilotOutputExporter.java
32 32
import eu.etaxonomy.cdm.model.taxon.Taxon;
33 33
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
34 34
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
35
import eu.etaxonomy.cdm.model.term.TermType;
35 36

  
36 37
/**
37 38
 * @author h.fradin (from a.babadshanjan)
......
239 240
		if (pilotOutputExpConfig.isDoFeatureData() == true) {
240 241
			if (featureDataRows == 0) { featureDataRows = MAX_ROWS; }
241 242
			logger.info("# Feature Tree, Feature Node");
242
			sddDataSet.setFeatureData(getFeatureTreeService().getFeatureNodesAll());
243
			sddDataSet.setFeatureData(getTermNodeService().list(TermType.Feature,null,null,null,null));
243 244
			sddDataSet.addFeatureData(getFeatureTreeService().list(null,null,null,null,null));
244 245
		}
245 246
	}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/sdd/out/SDDCdmExporter.java
37 37
import eu.etaxonomy.cdm.model.taxon.Taxon;
38 38
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
39 39
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
40
import eu.etaxonomy.cdm.model.term.TermType;
40 41

  
41 42
/**
42 43
 * @author h.fradin (from a.babadshanjan)
......
309 310
		if (sddExpConfig.isDoFeatureData() == true) {
310 311
			if (featureDataRows == 0) { featureDataRows = MAX_ROWS; }
311 312
			logger.info("# Feature Tree, Feature Node");
312
			sddDataSet.setFeatureData(getFeatureTreeService().getFeatureNodesAll());
313
			sddDataSet.setFeatureData(getTermNodeService().list(TermType.Feature,null,null,null,null));
313 314
			sddDataSet.addFeatureData(getFeatureTreeService().list(null,null,null,null,null));
314 315
		}
315 316
	}
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/description/ITermNodeDao.java
9 9
import java.util.List;
10 10

  
11 11
import eu.etaxonomy.cdm.model.term.TermNode;
12
import eu.etaxonomy.cdm.model.term.TermType;
12 13
import eu.etaxonomy.cdm.persistence.dao.common.IVersionableDao;
14
import eu.etaxonomy.cdm.persistence.query.OrderHint;
13 15

  
14 16
/**
15 17
 * @author a.babadshanjan
......
19 21

  
20 22
	public List<TermNode> list();
21 23

  
24
    /**
25
     * Loads a list of term nodes depending on the term type including included term types
26
     * @param termType the term type
27
     * @return
28
     */
29
    public List<TermNode> list(TermType termType, Integer limit, Integer start, List<OrderHint> orderHints,
30
            List<String> propertyPaths);
31

  
22 32
}
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/description/TermNodeDaoImpl.java
7 7
package eu.etaxonomy.cdm.persistence.dao.hibernate.description;
8 8

  
9 9
import java.util.List;
10
import java.util.Set;
10 11

  
11 12
import org.hibernate.Criteria;
13
import org.hibernate.criterion.Restrictions;
12 14
import org.springframework.stereotype.Repository;
13 15

  
14 16
import eu.etaxonomy.cdm.model.term.TermNode;
17
import eu.etaxonomy.cdm.model.term.TermType;
15 18
import eu.etaxonomy.cdm.persistence.dao.description.ITermNodeDao;
16 19
import eu.etaxonomy.cdm.persistence.dao.hibernate.common.VersionableDaoBase;
20
import eu.etaxonomy.cdm.persistence.query.OrderHint;
17 21

  
18 22
/**
19 23
 * @author a.babadshanjan
......
36 40
		return result;
37 41
	}
38 42

  
43
	//TODO still needs to be tested
44
	@Override
45
    public List<TermNode> list(TermType termType, Integer limit, Integer start, List<OrderHint> orderHints,
46
            List<String> propertyPaths){
47

  
48
	    Criteria criteria = getSession().createCriteria(type);
49
        if (termType != null){
50
            Set<TermType> types = termType.getGeneralizationOf(true);
51
            types.add(termType);
52
            criteria.add(Restrictions.in("termType", types));
53
        }
54

  
55
        addLimitAndStart(criteria, limit, start);
56

  
57
        addOrder(criteria, orderHints);
58

  
59
        @SuppressWarnings("unchecked")
60
        List<TermNode> results = criteria.list();
61

  
62
        defaultBeanInitializer.initializeAll(results, propertyPaths);
63
        return results;
64
	}
65

  
39 66
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/application/CdmApplicationController.java
62 62
import eu.etaxonomy.cdm.api.service.IRightsService;
63 63
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
64 64
import eu.etaxonomy.cdm.api.service.ITaxonService;
65
import eu.etaxonomy.cdm.api.service.ITermNodeService;
65 66
import eu.etaxonomy.cdm.api.service.ITermService;
67
import eu.etaxonomy.cdm.api.service.ITermTreeService;
66 68
import eu.etaxonomy.cdm.api.service.IUserService;
67 69
import eu.etaxonomy.cdm.api.service.IVocabularyService;
68 70
import eu.etaxonomy.cdm.api.service.molecular.IAmplificationService;
......
594 596
		return configuration.getFeatureTreeService();
595 597
	}
596 598

  
599
    @Override
600
    public final ITermTreeService getTermTreeService(){
601
        return configuration.getTermTreeService();
602
    }
603

  
597 604
	@Override
598 605
	public final IPreferenceService getPreferenceService(){
599 606
	    return configuration.getPreferenceService();
......
605 612
		return configuration.getFeatureNodeService();
606 613
	}
607 614

  
615
    @Override
616
    public final ITermNodeService getTermNodeService(){
617
        return configuration.getTermNodeService();
618
    }
619

  
608 620

  
609 621
	@Override
610 622
	public final IVocabularyService getVocabularyService(){
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/application/CdmRepository.java
63 63
import eu.etaxonomy.cdm.api.service.IRightsService;
64 64
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
65 65
import eu.etaxonomy.cdm.api.service.ITaxonService;
66
import eu.etaxonomy.cdm.api.service.ITermNodeService;
66 67
import eu.etaxonomy.cdm.api.service.ITermService;
68
import eu.etaxonomy.cdm.api.service.ITermTreeService;
67 69
import eu.etaxonomy.cdm.api.service.IUserService;
68 70
import eu.etaxonomy.cdm.api.service.IVocabularyService;
69 71
import eu.etaxonomy.cdm.api.service.molecular.IAmplificationService;
......
161 163
	@Autowired
162 164
	private IFeatureNodeService featureNodeService;
163 165
	@Autowired
166
	private ITermTreeService termTreeService;
167
	@Autowired
168
	private ITermNodeService termNodeService;
169
	@Autowired
164 170
	private IVocabularyService vocabularyService;
165 171
	@Autowired
166 172
	private ITaxonNodeService taxonNodeService;
......
365 371
	}
366 372

  
367 373
	@Override
374
	public ITermTreeService getTermTreeService(){
375
	    return termTreeService;
376
	}
377

  
378
	@Override
368 379
	public IFeatureNodeService getFeatureNodeService(){
369 380
		return featureNodeService;
370 381
	}
371 382

  
383
    @Override
384
    public ITermNodeService getTermNodeService(){
385
        return termNodeService;
386
    }
387

  
372 388
	@Override
373 389
    public IPreferenceService getPreferenceService(){
374 390
        return preferenceService;
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/application/ICdmRepository.java
44 44
import eu.etaxonomy.cdm.api.service.IRightsService;
45 45
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
46 46
import eu.etaxonomy.cdm.api.service.ITaxonService;
47
import eu.etaxonomy.cdm.api.service.ITermNodeService;
47 48
import eu.etaxonomy.cdm.api.service.ITermService;
49
import eu.etaxonomy.cdm.api.service.ITermTreeService;
48 50
import eu.etaxonomy.cdm.api.service.IUserService;
49 51
import eu.etaxonomy.cdm.api.service.IVocabularyService;
50 52
import eu.etaxonomy.cdm.api.service.molecular.IAmplificationService;
......
59 61
 */
60 62
public interface ICdmRepository{
61 63

  
62

  
63 64
    /**
64
     * Starts a read only Transaction
65
     * Starts a read only transaction
65 66
     */
66 67
    public TransactionStatus startTransaction();
67 68

  
......
71 72

  
72 73
	public Object getBean(String string);
73 74

  
74

  
75
	/**
76
     * @return
77
     */
78 75
    public IAnnotationService getAnnotationService();
79 76

  
80
	/**
81
	 * @return
82
	 */
83 77
	public INameService getNameService();
84 78

  
85

  
86
	/**
87
	 * @return
88
	 */
89 79
	public ITaxonService getTaxonService();
90 80

  
91

  
92
	/**
93
	 * @return
94
	 */
95 81
	public IClassificationService getClassificationService();
96 82

  
97

  
98
	/**
99
	 *
100
	 * @return
101
	 */
102 83
	public ITaxonNodeService getTaxonNodeService();
103 84

  
104

  
105
	/**
106
	 * @return
107
	 */
108 85
	public IReferenceService getReferenceService();
109 86

  
110

  
111
	/**
112
	 * @return
113
	 */
114 87
	public IAgentService getAgentService();
115 88

  
116

  
117
	/**
118
	 * @return
119
	 */
120 89
	public IDescriptionService getDescriptionService();
121 90

  
122

  
123
	/**
124
	 * @return
125
	 */
126 91
	public IOccurrenceService getOccurrenceService();
127 92

  
128

  
129
	/**
130
	 * @return
131
	 */
132 93
	public IPrimerService getPrimerService();
133 94

  
134

  
135
	/**
136
	 * @return
137
	 */
138 95
	public IAmplificationService getAmplificationService();
139 96

  
140

  
141
	/**
142
	 * @return
143
	 */
144 97
	public ISequenceService getSequenceService();
145 98

  
146 99
	public IEventBaseService getEventBaseService();
147 100

  
148

  
149
	/**
150
	 * @return
151
	 */
152 101
	public IMediaService getMediaService();
153 102

  
154
   /**
155
     * @return
156
     */
157 103
    public IMetadataService getMetadataService();
158 104

  
159

  
160
	/**
161
	 * @return
162
	 */
163 105
	public IDatabaseService getDatabaseService();
164 106

  
165

  
166
	/**
167
	 * @return
168
	 */
169 107
	public ITermService getTermService();
170 108

  
171

  
172
	/**
173
	 * @return
174
	 */
175 109
	public ICommonService getCommonService();
176 110

  
177

  
178
	/**
179
	 *
180
	 * @return
181
	 */
182 111
	public ILocationService getLocationService();
183 112

  
184

  
185
	/**
186
	 *
187
	 * @return
188
	 */
189 113
	public IUserService getUserService();
190 114

  
191

  
192
	/**
193
	 *
194
	 * @return
195
	 */
196 115
	public IGroupService getGroupService();
197 116

  
198
	/**
199
    *
200
    * @return
201
    */
202
   public IPreferenceService getPreferenceService();
117
    public IPreferenceService getPreferenceService();
203 118

  
204
	/**
205
	 *
206
	 * @return
207
	 */
208 119
	public IGrantedAuthorityService getGrantedAuthorityService();
209 120

  
210

  
211
	/**
212
	 * @return
213
	 */
214 121
	public IDescriptiveDataSetService getDescriptiveDataSetService();
215 122

  
216

  
217
	/**
218
	 * @return
219
	 */
220 123
	public PlatformTransactionManager getTransactionManager();
221 124

  
222

  
223
	/**
224
	 *
225
	 * @return
226
	 */
227 125
	public ProviderManager getAuthenticationManager();
228 126

  
229

  
230
	/**
231
	 * @return
232
	 */
233 127
	public ConversationHolder NewConversation();
234 128

  
235

  
236
	/**
237
	 *
238
	 * @return
239
	 */
240 129
	public ICollectionService getCollectionService();
241 130

  
242

  
243 131
	/**
244
	 *
245
	 * @return
132
	 * @deprecated use {@link #getTermTreeService()} instead
246 133
	 */
247
	public IFeatureTreeService getFeatureTreeService();
134
	@Deprecated
135
    public IFeatureTreeService getFeatureTreeService();
248 136

  
137
    public ITermTreeService getTermTreeService();
249 138

  
250 139
	/**
251
	 *
252
	 * @return
140
     * @deprecated use {@link #getTermNodeService()} instead
253 141
	 */
254
	public IFeatureNodeService getFeatureNodeService();
142
	@Deprecated
143
    public IFeatureNodeService getFeatureNodeService();
255 144

  
145
    /**
146
     * @return
147
     */
148
    public ITermNodeService getTermNodeService();
256 149

  
257
	/**
258
	 *
259
	 * @return
260
	 */
261 150
	public IVocabularyService getVocabularyService();
262 151

  
263

  
264
	/**
265
	 * @return
266
	 */
267 152
	public IIdentificationKeyService getIdentificationKeyService();
268 153

  
269

  
270
	/**
271
	 * @return
272
	 */
273 154
	public IPolytomousKeyService getPolytomousKeyService();
274 155

  
275

  
276
	/**
277
	 * @return
278
	 */
279 156
	public IPolytomousKeyNodeService getPolytomousKeyNodeService();
280 157

  
281
	/**
282
     * @return
283
     */
284 158
	public IProgressMonitorService getProgressMonitorService();
285 159

  
286
	/**
287
	 * @return
288
	 */
289 160
	public IEntityValidationService getEntityValidationService();
290 161

  
291
	/**
292
     * @return
293
     */
294 162
    public IRightsService getRightsService();
295 163

  
296
	/**
297
	 * @return
298
	 */
299 164
	public IEntityConstraintViolationService getEntityConstraintViolationService();
300 165

  
301

  
302 166
	/**
303 167
	 * @return the configured PermissionEvaluator, usually the
304 168
	 *         {@link CdmPermissionEvaluator}
305 169
	 */
306 170
	public ICdmPermissionEvaluator getPermissionEvaluator();
307 171

  
308

  
309 172
	void authenticate(String username, String password);
310 173

  
311
    /**
312
     * @return
313
     */
314
    IRegistrationService getRegistrationService();
174
    public IRegistrationService getRegistrationService();
315 175

  
316 176
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IFeatureNodeService.java
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.cdm.api.service;
11

  
12
import java.util.UUID;
13

  
14
import eu.etaxonomy.cdm.api.service.config.FeatureNodeDeletionConfigurator;
15
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
16
import eu.etaxonomy.cdm.model.term.TermNode;
17

  
18
/**
19
 * @author n.hoffmann
20
 * @since Aug 5, 2010
21
 */
22
public interface IFeatureNodeService extends IVersionableService<TermNode>{
23

  
24
    DeleteResult isDeletable(UUID nodeUuid, FeatureNodeDeletionConfigurator config);
25

  
26
    DeleteResult deleteFeatureNode(UUID nodeUuid, FeatureNodeDeletionConfigurator config);
27

  
28

  
29
    /**
30
     * <b>Saves</b> and adds the specified feature as a child node to the given feature node.
31
     * @see IFeatureNodeService#addChildFeatureNode(FeatureNode, DefinedTermBase)
32
     * @param parentNodeUuid the feature node where the new feature should be added
33
     * @param term the term which should be <b>saved</b> and added to the given feature node
34
     * @param vocabularyUuid the UUID of the vocabulary where the term should be saved
35
     * @return the result of the operation
36
     */
37
    public UpdateResult createChildFeatureNode(UUID parentNodeUuid, DefinedTermBase term, UUID vocabularyUuid);
38

  
39
    /**
40
     * Adds the specified feature as a child node to the given feature node
41
     * @param parentNodeUUID the UUID of the feature node where the new feature should be added
42
     * @param termChildUuid the UUID of the term which should be added to the given feature node
43
     * @return the result of the operation
44
     */
45
    public UpdateResult addChildFeatureNode(UUID parentNodeUUID, UUID termChildUuid);
46

  
47
    /**
48
     * Adds the specified feature as a child node to the given feature node at the given position
49
     * @param parentNodeUUID the UUID of the feature node where the new feature should be added
50
     * @param termChildUuid the UUID of the term which should be added to the given feature node
51
     * @param position the position where the child node should be added
52
     * @return the result of the operation
53
     */
54
    public UpdateResult addChildFeatureNode(UUID parentNodeUUID, UUID termChildUuid, int position);
55

  
56
    /**
57
     * Moves a given {@link TermNode} to the target node at the given position;
58
     * @param movedNodeUuid the node to move
59
     * @param targetNodeUuid the target node
60
     * @param position the position in the list of children of the target node
61
     * @return the result of the operation
62
     */
63
    public UpdateResult moveFeatureNode(UUID movedNodeUuid, UUID targetNodeUuid, int position);
64

  
65
    /**
66
     * Moves a given {@link TermNode} to the target node;
67
     * @param movedNodeUuid the node to move
68
     * @param targetNodeUuid the target node
69
     * @return the result of the operation
70
     */
71
    public UpdateResult moveFeatureNode(UUID movedNodeUuid, UUID targetNodeUuid);
72

  
73
}
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.cdm.api.service;
11

  
12
import java.util.UUID;
13

  
14
import eu.etaxonomy.cdm.api.service.config.TermNodeDeletionConfigurator;
15
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
16
import eu.etaxonomy.cdm.model.term.TermNode;
17

  
18
/**
19
 * @author n.hoffmann
20
 * @since Aug 5, 2010
21
 * @deprecated use ITermNodeService instead
22
 */
23
@Deprecated
24
public interface IFeatureNodeService extends IVersionableService<TermNode>{
25

  
26
    DeleteResult isDeletable(UUID nodeUuid, TermNodeDeletionConfigurator config);
27

  
28
    DeleteResult deleteFeatureNode(UUID nodeUuid, TermNodeDeletionConfigurator config);
29

  
30

  
31
    /**
32
     * <b>Saves</b> and adds the specified feature as a child node to the given feature node.
33
     * @see ITermNodeService#addChildFeatureNode(FeatureNode, DefinedTermBase)
34
     * @param parentNodeUuid the feature node where the new feature should be added
35
     * @param term the term which should be <b>saved</b> and added to the given feature node
36
     * @param vocabularyUuid the UUID of the vocabulary where the term should be saved
37
     * @return the result of the operation
38
     */
39
    public UpdateResult createChildFeatureNode(UUID parentNodeUuid, DefinedTermBase term, UUID vocabularyUuid);
40

  
41
    /**
42
     * Adds the specified feature as a child node to the given feature node
43
     * @param parentNodeUUID the UUID of the feature node where the new feature should be added
44
     * @param termChildUuid the UUID of the term which should be added to the given feature node
45
     * @return the result of the operation
46
     */
47
    public UpdateResult addChildFeatureNode(UUID parentNodeUUID, UUID termChildUuid);
48

  
49
    /**
50
     * Adds the specified feature as a child node to the given feature node at the given position
51
     * @param parentNodeUUID the UUID of the feature node where the new feature should be added
52
     * @param termChildUuid the UUID of the term which should be added to the given feature node
53
     * @param position the position where the child node should be added
54
     * @return the result of the operation
55
     */
56
    public UpdateResult addChildFeatureNode(UUID parentNodeUUID, UUID termChildUuid, int position);
57

  
58
    /**
59
     * Moves a given {@link TermNode} to the target node at the given position;
60
     * @param movedNodeUuid the node to move
61
     * @param targetNodeUuid the target node
62
     * @param position the position in the list of children of the target node
63
     * @return the result of the operation
64
     */
65
    public UpdateResult moveFeatureNode(UUID movedNodeUuid, UUID targetNodeUuid, int position);
66

  
67
    /**
68
     * Moves a given {@link TermNode} to the target node;
69
     * @param movedNodeUuid the node to move
70
     * @param targetNodeUuid the target node
71
     * @return the result of the operation
72
     */
73
    public UpdateResult moveFeatureNode(UUID movedNodeUuid, UUID targetNodeUuid);
74

  
75
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IFeatureTreeService.java
14 14
import java.util.Map;
15 15
import java.util.UUID;
16 16

  
17
import eu.etaxonomy.cdm.model.term.TermTree;
18 17
import eu.etaxonomy.cdm.model.term.TermNode;
18
import eu.etaxonomy.cdm.model.term.TermTree;
19 19
import eu.etaxonomy.cdm.model.term.TermType;
20 20
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
21 21

  
22
/**
23
* @deprecated use {@link ITermTreeService} instead
24
*/
25
@Deprecated
22 26
public interface IFeatureTreeService extends IIdentifiableEntityService<TermTree> {
23 27

  
24
	public List<TermNode> getFeatureNodesAll();
28
	/**
29
	 * @deprecated use {@link ITermTreeService#list(Class, Integer, Integer, List, List)} instead
30
	 */
31
	@Deprecated
32
    public List<TermNode> getFeatureNodesAll();
25 33

  
26 34
	/**
27 35
	 * Loads a feature tree including all of its nodes (all the way down to the tips of the tree).
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/ITermNodeService.java
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.cdm.api.service;
11

  
12
import java.util.List;
13
import java.util.UUID;
14

  
15
import eu.etaxonomy.cdm.api.service.config.TermNodeDeletionConfigurator;
16
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
17
import eu.etaxonomy.cdm.model.term.TermNode;
18
import eu.etaxonomy.cdm.model.term.TermType;
19
import eu.etaxonomy.cdm.persistence.query.OrderHint;
20

  
21
/**
22
 * @author n.hoffmann
23
 * @since Aug 5, 2010
24
 */
25
public interface ITermNodeService extends IVersionableService<TermNode>{
26

  
27
    public List<TermNode> list(TermType termType, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths);
28

  
29
    public DeleteResult isDeletable(UUID nodeUuid, TermNodeDeletionConfigurator config);
30

  
31
    public DeleteResult deleteNode(UUID nodeUuid, TermNodeDeletionConfigurator config);
32

  
33

  
34
    /**
35
     * <b>Saves</b> and adds the specified term as a child node to the given term node.
36
     * @see ITermNodeService#addChildNode(TermNode, DefinedTermBase)
37
     * @param parentNodeUuid the term node to which the new term should be added
38
     * @param term the term which should be <b>saved</b> and added to the given term node
39
     * @param vocabularyUuid the UUID of the vocabulary where the term should be saved
40
     * @return the result of the operation
41
     */
42
    public UpdateResult createChildNode(UUID parentNodeUuid, DefinedTermBase term, UUID vocabularyUuid);
43

  
44
    /**
45
     * Adds the specified term as a child node to the given term node
46
     * @param parentNodeUUID the UUID of the term node to which the new term should be added
47
     * @param termChildUuid the UUID of the term which should be added to the given term node
48
     * @return the result of the operation
49
     */
50
    public UpdateResult addChildNode(UUID parentNodeUUID, UUID termChildUuid);
51

  
52
    /**
53
     * Adds the specified term as a child node to the given term node at the given position
54
     * @param parentNodeUUID the UUID of the term node to which the new term should be added
55
     * @param termChildUuid the UUID of the term which should be added to the given term node
56
     * @param position the position where the child node should be added
57
     * @return the result of the operation
58
     */
59
    public UpdateResult addChildNode(UUID parentNodeUUID, UUID termChildUuid, int position);
60

  
61
    /**
62
     * Moves a given {@link TermNode} to the target node at the given position;
63
     * @param movedNodeUuid the node to move
64
     * @param targetNodeUuid the target node
65
     * @param position the position in the list of children of the target node
66
     * @return the result of the operation
67
     */
68
    public UpdateResult moveNode(UUID movedNodeUuid, UUID targetNodeUuid, int position);
69

  
70
    /**
71
     * Moves a given {@link TermNode} to the target node;
72
     * @param movedNodeUuid the node to move
73
     * @param targetNodeUuid the target node
74
     * @return the result of the operation
75
     */
76
    public UpdateResult moveNode(UUID movedNodeUuid, UUID targetNodeUuid);
77

  
78
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/ITermTreeService.java
1
/**
2
* Copyright (C) 2009 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.cdm.api.service;
11

  
12
import java.util.Collection;
13
import java.util.List;
14
import java.util.Map;
15
import java.util.UUID;
16

  
17
import eu.etaxonomy.cdm.model.description.Feature;
18
import eu.etaxonomy.cdm.model.term.TermNode;
19
import eu.etaxonomy.cdm.model.term.TermTree;
20
import eu.etaxonomy.cdm.model.term.TermType;
21
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
22

  
23
public interface ITermTreeService extends IIdentifiableEntityService<TermTree> {
24

  
25
	/**
26
	 * Loads a term tree including all of its nodes (all the way down to the tips of the tree).
27
	 * Because this method automatically adds term nodes recursively, adding "root" to property paths
28
	 * is superfluous - the propertyPaths argument should be used to initialize property paths <i>in addition</i>
29
	 * to the term nodes. The nodePaths argument is applied to each node in turn, so again, adding "children"
30
	 * is also superfluous. The nodePaths argument should be used to specify additional properties of the term node
31
	 * to initialize (e.g. feature).
32
	 *
33
	 */
34
	public TermTree loadWithNodes(UUID uuid, List<String> propertyPaths, List<String> nodePaths);
35

  
36
	public Map<UUID, TermNode> saveNodesAll(Collection<TermNode> featureNodeCollection);
37

  
38
	public Map<UUID, TermNode> saveOrUpdateNodesAll(Collection<TermNode> featureNodeCollection);
39

  
40
	public TermTree<Feature> createTransientDefaultFeatureTree();
41

  
42
	public <S extends TermTree> List<UuidAndTitleCache<S>> getUuidAndTitleCacheByTermType(
43
	        Class<S> clazz, TermType termType, Integer limit, String pattern);
44
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TermNodeServiceImpl.java
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.cdm.api.service;
11

  
12
import java.util.ArrayList;
13
import java.util.List;
14
import java.util.Set;
15
import java.util.UUID;
16

  
17
import org.apache.log4j.Logger;
18
import org.springframework.beans.factory.annotation.Autowired;
19
import org.springframework.stereotype.Service;
20
import org.springframework.transaction.annotation.Transactional;
21

  
22
import eu.etaxonomy.cdm.api.service.config.NodeDeletionConfigurator.ChildHandling;
23
import eu.etaxonomy.cdm.api.service.config.TermNodeDeletionConfigurator;
24
import eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException;
25
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
26
import eu.etaxonomy.cdm.model.common.CdmBase;
27
import eu.etaxonomy.cdm.model.description.Feature;
28
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
29
import eu.etaxonomy.cdm.model.term.TermNode;
30
import eu.etaxonomy.cdm.model.term.TermTree;
31
import eu.etaxonomy.cdm.model.term.TermType;
32
import eu.etaxonomy.cdm.model.term.TermVocabulary;
33
import eu.etaxonomy.cdm.persistence.dao.description.ITermNodeDao;
34
import eu.etaxonomy.cdm.persistence.query.OrderHint;
35

  
36
/**
37
 * @author a.mueller
38
 * @since Jul 22, 2019
39
 */
40
@Service
41
@Transactional(readOnly = false)
42
public class TermNodeServiceImpl
43
        extends VersionableServiceBase<TermNode, ITermNodeDao>
44
        implements ITermNodeService {
45

  
46
    @SuppressWarnings("unused")
47
    private static final Logger logger = Logger.getLogger(TermNodeServiceImpl.class);
48

  
49
	@Override
50
    @Autowired
51
	protected void setDao(ITermNodeDao dao) {
52
		this.dao = dao;
53
	}
54

  
55
	@Autowired
56
    private ITermService termService;
57

  
58
	@Autowired
59
	private IVocabularyService vocabularyService;
60

  
61
	@Override
62
    public List<TermNode> list(TermType termType, Integer limit, Integer start,
63
	        List<OrderHint> orderHints, List<String> propertyPaths){
64
	    return dao.list(termType, limit, start, orderHints, propertyPaths);
65
	}
66

  
67
	@Override
68
	@Transactional(readOnly = false)
69
	public DeleteResult deleteNode(UUID nodeUuid, TermNodeDeletionConfigurator config) {
70
	    DeleteResult result = new DeleteResult();
71
        TermNode<Feature> node = CdmBase.deproxy(dao.load(nodeUuid));
72
	    result = isDeletable(nodeUuid, config);
73
	    if (result.isOk()){
74
	        TermNode<Feature> parent = node.getParent();
75
            parent = CdmBase.deproxy(parent, TermNode.class);
76
	        List<TermNode> children = new ArrayList<>(node.getChildNodes());
77

  
78
	        if (config.getChildHandling().equals(ChildHandling.DELETE)){
79

  
80
	            for (TermNode child: children){
81
	                deleteNode(child.getUuid(), config);
82
	               // node.removeChild(child);
83
	            }
84
	            if (parent != null){
85
	                parent.removeChild(node);
86
	            }
87

  
88
	        } else{
89

  
90
	            if (parent != null){
91
	                parent.removeChild(node);
92
	                for (TermNode child: children){
93
	                    node.removeChild(child);
94
	                    parent.addChild(child);
95
	                }
96
	            }else{
97
	                 result.setAbort();
98
	                 result.addException(new ReferencedObjectUndeletableException("The root node can not be deleted without its child nodes"));
99
	                 return result;
100
	             }
101
	         }
102

  
103
	         dao.delete(node);
104
	         result.addDeletedObject(node);
105
	         if(parent!=null){
106
	             result.addUpdatedObject(parent);
107
	         }
108
	         if (config.isDeleteElement()){
109
	             DefinedTermBase term = node.getTerm();
110
                 termService.delete(term.getUuid());
111
                 result.addDeletedObject(term);
112
             }
113
	     }
114
	     return result;
115
	 }
116

  
117
	 @Override
118
     public UpdateResult createChildNode(UUID parentNodeUuid, DefinedTermBase term, UUID vocabularyUuid){
119
	     TermVocabulary vocabulary = vocabularyService.load(vocabularyUuid);
120

  
121
	     vocabulary.addTerm(term);
122
	     vocabularyService.save(vocabulary);
123
	     return addChildNode(parentNodeUuid, term.getUuid());
124
	 }
125

  
126
     @Override
127
     public UpdateResult addChildNode(UUID nodeUUID, UUID termChildUuid){
128
         return addChildNode(nodeUUID, termChildUuid, 0);
129
     }
130

  
131
	 @Override
132
	 public UpdateResult addChildNode(UUID nodeUUID, UUID termChildUuid, int position){
133
	     TermNode node = load(nodeUUID);
134
	     DefinedTermBase child = HibernateProxyHelper.deproxy(termService.load(termChildUuid), DefinedTermBase.class);
135

  
136
	     TermNode childNode;
137
         UpdateResult result = new UpdateResult();
138
         if(position<0) {
139
             childNode = node.addChild(child);
140
         }
141
         else{
142
             childNode = node.addChild(child, position);
143
         }
144
         save(childNode);
145
         result.addUpdatedObject(node);
146
         result.setCdmEntity(childNode);
147
         return result;
148
     }
149

  
150
	 @Override
151
	 public DeleteResult isDeletable(UUID nodeUuid, TermNodeDeletionConfigurator config){
152
	     TermNode<Feature> node = load(nodeUuid);
153
	     DeleteResult result = new DeleteResult();
154
	     Set<CdmBase> references = commonService.getReferencingObjectsForDeletion(node);
155
	     for (CdmBase ref:references){
156
	         if (ref instanceof TermNode){
157
	             break;
158
	         }
159
	         if (ref instanceof TermTree){
160
	             TermTree<Feature> refTree = HibernateProxyHelper.deproxy(ref, TermTree.class);
161
	             if (node.getGraph().equals((refTree))){
162
	                 break;
163
	             }
164
	         }
165
	         result.setAbort();
166
	         result.addException(new ReferencedObjectUndeletableException("The featureNode is referenced by " + ref.getUserFriendlyDescription() +" with id " +ref.getId()));
167

  
168
	     }
169
	     return result;
170
	 }
171

  
172
    /**
173
     * {@inheritDoc}
174
     */
175
    @Override
176
    public UpdateResult moveNode(UUID movedNodeUuid, UUID targetNodeUuid, int position) {
177
        UpdateResult result = new UpdateResult();
178
        TermNode movedNode = CdmBase.deproxy(load(movedNodeUuid));
179
        TermNode targetNode = CdmBase.deproxy(load(targetNodeUuid));
180
        TermNode parent = CdmBase.deproxy(movedNode.getParent());
181
        if(position < 0){
182
            targetNode.addChild(movedNode);
183
        }
184
        else{
185
            targetNode.addChild(movedNode, position);
186
        }
187
        result.addUpdatedObject(targetNode);
188
        if(parent!=null){
189
            result.addUpdatedObject(parent);
190
        }
191
        result.setCdmEntity(movedNode);
192
        return result;
193
    }
194

  
195
    /**
196
     * {@inheritDoc}
197
     */
198
    @Override
199
    public UpdateResult moveNode(UUID movedNodeUuid, UUID targetNodeUuid) {
200
        return moveNode(movedNodeUuid, targetNodeUuid, -1);
201
    }
202

  
203
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TermTreeServiceImpl.java
1
/**
2
* Copyright (C) 2009 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.cdm.api.service;
11

  
12
import java.util.ArrayList;
13
import java.util.Collection;
14
import java.util.List;
15
import java.util.Map;
16
import java.util.UUID;
17

  
18
import javax.persistence.EntityNotFoundException;
19

  
20
import org.springframework.beans.factory.annotation.Autowired;
21
import org.springframework.stereotype.Service;
22
import org.springframework.transaction.annotation.Transactional;
23

  
24
import eu.etaxonomy.cdm.api.service.config.NodeDeletionConfigurator.ChildHandling;
25
import eu.etaxonomy.cdm.api.service.config.TermNodeDeletionConfigurator;
26
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
27
import eu.etaxonomy.cdm.model.common.CdmBase;
28
import eu.etaxonomy.cdm.model.description.Feature;
29
import eu.etaxonomy.cdm.model.term.TermNode;
30
import eu.etaxonomy.cdm.model.term.TermTree;
31
import eu.etaxonomy.cdm.model.term.TermType;
32
import eu.etaxonomy.cdm.persistence.dao.description.IFeatureTreeDao;
33
import eu.etaxonomy.cdm.persistence.dao.description.ITermNodeDao;
34
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
35
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
36

  
37
@Service
38
@Transactional(readOnly = false)
39
public class TermTreeServiceImpl
40
            extends IdentifiableServiceBase<TermTree, IFeatureTreeDao>
41
            implements ITermTreeService {
42

  
43
    private ITermNodeDao termNodeDao;
44

  
45
    @Autowired
46
    private ITermNodeService termNodeService;
47

  
48
    @Override
49
    @Autowired
50
    protected void setDao(IFeatureTreeDao dao) {
51
        this.dao = dao;
52
    }
53

  
54
    @Autowired
55
    protected void setTermNodeDao(ITermNodeDao termNodeDao) {
56
        this.termNodeDao = termNodeDao;
57
    }
58

  
59
    @Override
60
    @Transactional(readOnly = false)
61
    public UpdateResult updateCaches(Class<? extends TermTree> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<TermTree> cacheStrategy, IProgressMonitor monitor) {
62
        if (clazz == null){
63
            clazz = TermTree.class;
64
        }
65
        return super.updateCachesImpl(clazz, stepSize, cacheStrategy, monitor);
66
    }
67

  
68
    @Override
69
    public Map<UUID, TermNode> saveNodesAll(Collection<TermNode> nodeCollection) {
70
        return termNodeDao.saveAll(nodeCollection);
71
    }
72

  
73
    @Override
74
    public Map<UUID, TermNode> saveOrUpdateNodesAll(Collection<TermNode> nodeCollection) {
75
        return termNodeDao.saveOrUpdateAll(nodeCollection);
76
    }
77

  
78
    @Override
79
    public TermTree loadWithNodes(UUID uuid, List<String> propertyPaths, List<String> nodePaths) {
80

  
81
        if(nodePaths==null){
82
            nodePaths = new ArrayList<>();
83
        }
84

  
85
        if(!nodePaths.contains("children")) {
86
            nodePaths.add("children");
87
        }
88

  
89
        List<String> rootPaths = new ArrayList<>();
90
        rootPaths.add("root");
91
        for(String path : nodePaths) {
92
            rootPaths.add("root." + path);
93
        }
94

  
95
        if(propertyPaths != null) {
96
            rootPaths.addAll(propertyPaths);
97
        }
98

  
99
        TermTree featureTree = load(uuid, rootPaths);
100
        if(featureTree == null){
101
            throw new EntityNotFoundException("No FeatureTree entity found for " + uuid);
102
        }
103
        dao.deepLoadNodes(featureTree.getRoot().getChildNodes(), nodePaths);
104
        return featureTree;
105
    }
106

  
107
    /**
108
     * Returns the featureTree specified by the given <code>uuid</code>.
109
     * The specified featureTree either can be one of those stored in the CDM database or can be the
110
     * DefaultFeatureTree (contains all Features in use).
111
     * The uuid of the DefaultFeatureTree is defined in {@link IFeatureTreeService#DefaultFeatureTreeUuid}.
112
     * The DefaultFeatureTree is also returned if no feature tree at all is stored in the cdm database.
113
     *
114
     * @see eu.etaxonomy.cdm.api.service.ServiceBase#load(java.util.UUID, java.util.List)
115
     */
116
    @Override
117
    public TermTree load(UUID uuid, List<String> propertyPaths) {
118
        return super.load(uuid, propertyPaths);
119
    }
120

  
121
    @Override
122
    public TermTree<Feature> createTransientDefaultFeatureTree() {
123
        return load(IFeatureTreeDao.DefaultFeatureTreeUuid);
124
    }
125

  
126
    @Override
127
    public DeleteResult delete(UUID featureTreeUuid){
128
        DeleteResult result = new DeleteResult();
129
        TermTree tree = dao.load(featureTreeUuid);
130

  
131
        TermNode rootNode = CdmBase.deproxy(tree.getRoot());
132
        TermNodeDeletionConfigurator config = new TermNodeDeletionConfigurator();
133
        config.setChildHandling(ChildHandling.DELETE);
134
        result = termNodeService.deleteNode(rootNode.getUuid(), config);
135
        //FIXME test if this is necessary
136
        tree.removeRootNode();
137
        if (result.isOk()){
138
          dao.delete(tree);
139
          result.addDeletedObject(tree);
140
        }
141
        return result;
142
    }
143

  
144
    @Override
145
    public <S extends TermTree> List<UuidAndTitleCache<S>> getUuidAndTitleCacheByTermType(Class<S> clazz, TermType termType, Integer limit,
146
            String pattern) {
147
        return dao.getUuidAndTitleCacheByTermType(clazz, termType, limit, pattern);
148
    }
149

  
150

  
151
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)