1
|
/**
|
2
|
* Copyright (C) 2013 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.cdm.remote.controller.util;
|
10
|
|
11
|
import java.util.HashSet;
|
12
|
import java.util.Set;
|
13
|
import java.util.UUID;
|
14
|
|
15
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
16
|
import eu.etaxonomy.cdm.api.service.util.TaxonRelationshipEdge;
|
17
|
import eu.etaxonomy.cdm.model.common.RelationshipBase.Direction;
|
18
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
|
19
|
import eu.etaxonomy.cdm.remote.editor.UuidList;
|
20
|
|
21
|
/**
|
22
|
* @author a.kohlbecker
|
23
|
* @date Jan 24, 2013
|
24
|
*
|
25
|
*/
|
26
|
public class ControllerUtils {
|
27
|
|
28
|
/**
|
29
|
* @param relationshipUuids
|
30
|
* @param relationshipInversUuids
|
31
|
* @param includeRelationships
|
32
|
* @return
|
33
|
*/
|
34
|
public static Set<TaxonRelationshipEdge> loadIncludeRelationships(UuidList relationshipUuids, UuidList relationshipInversUuids, ITermService termService) {
|
35
|
Set<TaxonRelationshipEdge> includeRelationships = null;
|
36
|
if(relationshipUuids != null || relationshipInversUuids != null){
|
37
|
includeRelationships = new HashSet<TaxonRelationshipEdge>();
|
38
|
if(relationshipUuids != null) {
|
39
|
for (UUID uuid : relationshipUuids) {
|
40
|
if(relationshipInversUuids != null && relationshipInversUuids.contains(uuid)){
|
41
|
includeRelationships.add(new TaxonRelationshipEdge((TaxonRelationshipType) termService.find(uuid), Direction.relatedTo, Direction.relatedFrom));
|
42
|
relationshipInversUuids.remove(uuid);
|
43
|
} else {
|
44
|
includeRelationships.add(new TaxonRelationshipEdge((TaxonRelationshipType) termService.find(uuid), Direction.relatedTo));
|
45
|
}
|
46
|
}
|
47
|
}
|
48
|
if(relationshipInversUuids != null) {
|
49
|
for (UUID uuid : relationshipInversUuids) {
|
50
|
includeRelationships.add(new TaxonRelationshipEdge((TaxonRelationshipType) termService.find(uuid), Direction.relatedFrom));
|
51
|
}
|
52
|
}
|
53
|
}
|
54
|
return includeRelationships;
|
55
|
}
|
56
|
|
57
|
|
58
|
}
|