1
|
package eu.dnetlib.server.widget;
|
2
|
|
3
|
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
4
|
import eu.dnetlib.client.widgets.AutoCompleteService;
|
5
|
import eu.dnetlib.goldoa.domain.Vocabulary;
|
6
|
import eu.dnetlib.goldoa.service.SearchManager;
|
7
|
import org.springframework.context.ApplicationContext;
|
8
|
import org.springframework.web.context.support.WebApplicationContextUtils;
|
9
|
|
10
|
import javax.servlet.ServletConfig;
|
11
|
import javax.servlet.ServletException;
|
12
|
import java.util.ArrayList;
|
13
|
import java.util.List;
|
14
|
|
15
|
/**
|
16
|
* Created by stefania on 3/2/15.
|
17
|
*/
|
18
|
public class AutoCompleteServiceImpl extends RemoteServiceServlet implements AutoCompleteService {
|
19
|
|
20
|
private SearchManager searchManager = null;
|
21
|
|
22
|
public void init(ServletConfig config) throws ServletException {
|
23
|
|
24
|
super.init(config);
|
25
|
|
26
|
ApplicationContext context = WebApplicationContextUtils
|
27
|
.getWebApplicationContext(getServletContext());
|
28
|
|
29
|
this.searchManager = (SearchManager) context.getBean("searchManager");
|
30
|
}
|
31
|
|
32
|
@Override
|
33
|
public List<Vocabulary> getAutoCompleteVocabulary(String type, String matchString) {
|
34
|
|
35
|
List<Vocabulary> matchingNames = new ArrayList<Vocabulary>();
|
36
|
|
37
|
try {
|
38
|
SearchManager.TYPE searchType = SearchManager.TYPE.ORGANISATION;
|
39
|
if (type.equals("project"))
|
40
|
searchType = SearchManager.TYPE.PROJECT;
|
41
|
else if (type.equals("organisation"))
|
42
|
searchType = SearchManager.TYPE.ORGANISATION;
|
43
|
else if (type.equals("journal"))
|
44
|
searchType = SearchManager.TYPE.JOURNAL;
|
45
|
else if (type.equals("publisher"))
|
46
|
searchType = SearchManager.TYPE.PUBLISHER;
|
47
|
else if (type.equals("funder"))
|
48
|
searchType = SearchManager.TYPE.FUNDER;
|
49
|
|
50
|
|
51
|
List<Vocabulary> vocabularyList = searchManager.search(searchType, matchString);
|
52
|
|
53
|
|
54
|
for (Vocabulary vocabulary : vocabularyList) {
|
55
|
matchingNames.add(new Vocabulary(vocabulary.getId(), vocabulary.getName(),null));
|
56
|
}
|
57
|
} catch(Exception e) {
|
58
|
e.printStackTrace();
|
59
|
}
|
60
|
|
61
|
return matchingNames;
|
62
|
}
|
63
|
}
|