1 |
19b0f922
|
m.doering
|
package eu.etaxonomy.cdm.remote.service;
|
2 |
|
|
|
3 |
765e852b
|
m.doering
|
import java.util.ArrayList;
|
4 |
19b0f922
|
m.doering
|
import java.util.List;
|
5 |
6e1e4b0f
|
m.doering
|
import java.util.Random;
|
6 |
|
|
import java.util.Set;
|
7 |
19b0f922
|
m.doering
|
import java.util.UUID;
|
8 |
|
|
|
9 |
6e1e4b0f
|
m.doering
|
import org.springframework.beans.factory.annotation.Autowired;
|
10 |
b5d18cd8
|
m.doering
|
import org.springframework.stereotype.Component;
|
11 |
7a42ba04
|
m.doering
|
import org.springframework.transaction.annotation.Transactional;
|
12 |
b5d18cd8
|
m.doering
|
|
13 |
b7cfab0e
|
m.doering
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
14 |
|
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
15 |
|
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
16 |
a47f5874
|
m.doering
|
import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao;
|
17 |
6e1e4b0f
|
m.doering
|
import eu.etaxonomy.cdm.remote.dto.NameSTO;
|
18 |
19b0f922
|
m.doering
|
import eu.etaxonomy.cdm.remote.dto.NameTO;
|
19 |
b7cfab0e
|
m.doering
|
import eu.etaxonomy.cdm.remote.dto.ReferenceSTO;
|
20 |
|
|
import eu.etaxonomy.cdm.remote.dto.ReferenceTO;
|
21 |
|
|
import eu.etaxonomy.cdm.remote.dto.ReferencedEntityBaseSTO;
|
22 |
6e1e4b0f
|
m.doering
|
import eu.etaxonomy.cdm.remote.dto.ResultSetPageSTO;
|
23 |
765e852b
|
m.doering
|
import eu.etaxonomy.cdm.remote.dto.TagEnum;
|
24 |
|
|
import eu.etaxonomy.cdm.remote.dto.TaggedText;
|
25 |
19b0f922
|
m.doering
|
import eu.etaxonomy.cdm.remote.dto.TaxonSTO;
|
26 |
|
|
import eu.etaxonomy.cdm.remote.dto.TaxonTO;
|
27 |
6e1e4b0f
|
m.doering
|
import eu.etaxonomy.cdm.remote.dto.TreeNode;
|
28 |
a47f5874
|
m.doering
|
import eu.etaxonomy.cdm.remote.dto.assembler.NameAssembler;
|
29 |
|
|
import eu.etaxonomy.cdm.remote.dto.assembler.TaxonAssembler;
|
30 |
19b0f922
|
m.doering
|
|
31 |
b5d18cd8
|
m.doering
|
@Component
|
32 |
7a42ba04
|
m.doering
|
@Transactional(readOnly = true)
|
33 |
02c32709
|
m.doering
|
public class CdmServiceImpl implements ICdmService {
|
34 |
19b0f922
|
m.doering
|
|
35 |
6e1e4b0f
|
m.doering
|
@Autowired
|
36 |
a47f5874
|
m.doering
|
private NameAssembler nameAssembler;
|
37 |
6e1e4b0f
|
m.doering
|
@Autowired
|
38 |
a47f5874
|
m.doering
|
private TaxonAssembler taxonAssembler;
|
39 |
|
|
@Autowired
|
40 |
|
|
private ITaxonDao taxonDAO;
|
41 |
|
|
|
42 |
6e1e4b0f
|
m.doering
|
|
43 |
b7cfab0e
|
m.doering
|
/**
|
44 |
|
|
* find matching taxonbase instance and take care of errorhandling for springmvc
|
45 |
|
|
* @param uuid
|
46 |
|
|
* @return
|
47 |
6960ca08
|
m.doering
|
* @throws CdmObjectNonExisting
|
48 |
b7cfab0e
|
m.doering
|
*/
|
49 |
6960ca08
|
m.doering
|
private TaxonBase getCdmTaxonBase(UUID uuid) throws CdmObjectNonExisting{
|
50 |
|
|
TaxonBase tb = taxonDAO.findByUuid(uuid);
|
51 |
|
|
if (tb==null){
|
52 |
|
|
throw new CdmObjectNonExisting(uuid, TaxonBase.class);
|
53 |
|
|
}
|
54 |
|
|
return tb;
|
55 |
b7cfab0e
|
m.doering
|
}
|
56 |
6960ca08
|
m.doering
|
private Taxon getCdmTaxon(UUID uuid) throws CdmObjectNonExisting{
|
57 |
|
|
Taxon t = null;
|
58 |
|
|
try {
|
59 |
|
|
t = (Taxon) getCdmTaxonBase(uuid);
|
60 |
|
|
} catch (ClassCastException e) {
|
61 |
|
|
throw new CdmObjectNonExisting(uuid, Taxon.class);
|
62 |
|
|
}
|
63 |
|
|
return t;
|
64 |
b7cfab0e
|
m.doering
|
}
|
65 |
|
|
|
66 |
6960ca08
|
m.doering
|
public NameTO getName(UUID uuid) throws CdmObjectNonExisting{
|
67 |
a47f5874
|
m.doering
|
// FIXME: use real name DAO not taxon DAO!
|
68 |
b7cfab0e
|
m.doering
|
NameTO n = nameAssembler.getTO(getCdmTaxonBase(uuid).getName());
|
69 |
c582c292
|
m.doering
|
return n;
|
70 |
19b0f922
|
m.doering
|
}
|
71 |
6e1e4b0f
|
m.doering
|
|
72 |
6960ca08
|
m.doering
|
public TaxonTO getTaxon(UUID uuid) throws CdmObjectNonExisting{
|
73 |
b7cfab0e
|
m.doering
|
TaxonTO t = taxonAssembler.getTO(getCdmTaxonBase(uuid));
|
74 |
c582c292
|
m.doering
|
return t;
|
75 |
19b0f922
|
m.doering
|
}
|
76 |
6e1e4b0f
|
m.doering
|
|
77 |
6960ca08
|
m.doering
|
public Class whatis(UUID uuid) throws CdmObjectNonExisting{
|
78 |
c582c292
|
m.doering
|
return this.getClass();
|
79 |
19b0f922
|
m.doering
|
}
|
80 |
|
|
|
81 |
64b85721
|
m.doering
|
public ResultSetPageSTO<TaxonSTO> findTaxa(String q, UUID sec,Set<UUID> higherTaxa, boolean matchAnywhere, boolean onlyAccepted, int page, int pagesize) {
|
82 |
53c0355c
|
m.doering
|
Random random = new Random();
|
83 |
6e1e4b0f
|
m.doering
|
ResultSetPageSTO<TaxonSTO> rs = new ResultSetPageSTO<TaxonSTO>();
|
84 |
12a21cf5
|
m.doering
|
rs.setPageSize(pagesize);
|
85 |
|
|
rs.setPageNumber(page);
|
86 |
6e1e4b0f
|
m.doering
|
// random results
|
87 |
12a21cf5
|
m.doering
|
int x = random.nextInt(30);
|
88 |
|
|
rs.setTotalResultsCount(x);
|
89 |
6e1e4b0f
|
m.doering
|
for (int i=0; i<rs.getResultsOnPage(); i++){
|
90 |
a47f5874
|
m.doering
|
TaxonSTO tx = taxonAssembler.getRandom();
|
91 |
12a21cf5
|
m.doering
|
rs.getResults().add(tx);
|
92 |
6e1e4b0f
|
m.doering
|
}
|
93 |
|
|
// result set metadata
|
94 |
|
|
return rs;
|
95 |
|
|
}
|
96 |
|
|
|
97 |
6960ca08
|
m.doering
|
public ResultSetPageSTO<TaxonSTO> getAcceptedTaxon(UUID uuid) throws CdmObjectNonExisting {
|
98 |
b7cfab0e
|
m.doering
|
TaxonBase tb = getCdmTaxonBase(uuid);
|
99 |
|
|
ResultSetPageSTO<TaxonSTO> rs = new ResultSetPageSTO<TaxonSTO>();
|
100 |
|
|
rs.setPageNumber(1);
|
101 |
|
|
rs.setPageSize(25);
|
102 |
|
|
if (tb.getClass().equals(Taxon.class)){
|
103 |
|
|
TaxonSTO t = taxonAssembler.getSTO(tb);
|
104 |
|
|
rs.addResultToFirstPage(t);
|
105 |
|
|
}else{
|
106 |
|
|
Synonym s = (Synonym)tb;
|
107 |
|
|
Set<Taxon> taxa = s.getAcceptedTaxa();
|
108 |
|
|
for (Taxon tx: taxa){
|
109 |
|
|
TaxonSTO t = taxonAssembler.getSTO(tx);
|
110 |
|
|
rs.addResultToFirstPage(t);
|
111 |
|
|
}
|
112 |
|
|
}
|
113 |
|
|
return rs;
|
114 |
|
|
}
|
115 |
|
|
|
116 |
|
|
public Set<ReferenceSTO> getAllSecReferences() {
|
117 |
|
|
// TODO Auto-generated method stub
|
118 |
|
|
return null;
|
119 |
|
|
}
|
120 |
|
|
|
121 |
6960ca08
|
m.doering
|
public List<TreeNode> getChildrenTaxa(UUID uuid) throws CdmObjectNonExisting {
|
122 |
b7cfab0e
|
m.doering
|
ArrayList<TreeNode> result = new ArrayList<TreeNode>();
|
123 |
|
|
Taxon tx = getCdmTaxon(uuid);
|
124 |
|
|
for (Taxon t : tx.getTaxonomicChildren()){
|
125 |
|
|
result.add(taxonAssembler.getTreeNode(t));
|
126 |
|
|
}
|
127 |
|
|
return result;
|
128 |
|
|
}
|
129 |
|
|
|
130 |
6960ca08
|
m.doering
|
public List<TreeNode> getParentTaxa(UUID uuid) throws CdmObjectNonExisting {
|
131 |
b7cfab0e
|
m.doering
|
ArrayList<TreeNode> result = new ArrayList<TreeNode>();
|
132 |
|
|
Taxon tx = getCdmTaxon(uuid);
|
133 |
|
|
result.add(taxonAssembler.getTreeNode(tx));
|
134 |
|
|
while(tx.getTaxonomicParent() != null){
|
135 |
|
|
Taxon parent = tx.getTaxonomicParent();
|
136 |
|
|
result.add(taxonAssembler.getTreeNode(parent));
|
137 |
|
|
tx=parent;
|
138 |
|
|
}
|
139 |
|
|
return result;
|
140 |
|
|
}
|
141 |
|
|
|
142 |
|
|
public ReferenceTO getReference(UUID uuid) {
|
143 |
|
|
// TODO Auto-generated method stub
|
144 |
|
|
return null;
|
145 |
|
|
}
|
146 |
|
|
|
147 |
|
|
public List<TreeNode> getRootTaxa(UUID uuid) {
|
148 |
6960ca08
|
m.doering
|
List<Taxon> taxa = taxonDAO.getRootTaxa(null);
|
149 |
|
|
return taxonAssembler.getTreeNodeList(taxa.toArray(new Taxon[0]));
|
150 |
6e1e4b0f
|
m.doering
|
}
|
151 |
c582c292
|
m.doering
|
|
152 |
b7cfab0e
|
m.doering
|
public Set<ReferencedEntityBaseSTO> getTypes(UUID uuid) {
|
153 |
|
|
// TODO Auto-generated method stub
|
154 |
|
|
return null;
|
155 |
|
|
}
|
156 |
|
|
|
157 |
|
|
|
158 |
|
|
|
159 |
19b0f922
|
m.doering
|
}
|