Project

General

Profile

1 32999 michele.ar
package eu.dnetlib.functionality.modular.ui.repositories;
2
3
import java.util.ArrayList;
4
import java.util.List;
5
import java.util.Map;
6
7
import javax.annotation.Resource;
8
import javax.servlet.http.HttpServletRequest;
9
import javax.servlet.http.HttpServletResponse;
10
11
import org.springframework.beans.factory.annotation.Required;
12
import org.springframework.ui.ModelMap;
13
14
import com.google.common.base.Function;
15
import com.google.common.collect.Lists;
16
import com.google.common.collect.Maps;
17
import com.google.gson.Gson;
18
19
import eu.dnetlib.data.collector.rmi.CollectorService;
20
import eu.dnetlib.data.collector.rmi.ProtocolDescriptor;
21 33226 michele.ar
import eu.dnetlib.data.collector.rmi.ProtocolParameter;
22 32999 michele.ar
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
23
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
24
import eu.dnetlib.functionality.modular.ui.ModuleEntryPoint;
25
import eu.dnetlib.functionality.modular.ui.repositories.objects.VocabularyEntry;
26
27
public class AddRepoApiEntryPointController extends ModuleEntryPoint {
28
29
	private String datasourceTypeVocabulary;
30
	private String complianceVocabulary;
31
	private String contentDescriptionsVocabulary;
32
	private String protocolsVocabulary;
33
34
	@Resource
35
	private UniqueServiceLocator serviceLocator;
36
37 33745 michele.ar
	@Resource
38
	private RepoUIUtils repoUIUtils;
39
40 32999 michele.ar
	@Override
41
	protected void initialize(final ModelMap map, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
42
		final Gson gson = new Gson();
43 33745 michele.ar
		map.addAttribute("types", gson.toJson(repoUIUtils.fetchVocabularyTerms(datasourceTypeVocabulary)));
44
		map.addAttribute("compliances", gson.toJson(repoUIUtils.fetchVocabularyTerms(complianceVocabulary)));
45
		map.addAttribute("contentDescriptions", gson.toJson(repoUIUtils.fetchVocabularyTerms(contentDescriptionsVocabulary)));
46 32999 michele.ar
		map.addAttribute("protocols", gson.toJson(listProtocols()));
47
	}
48
49
	private List<ProtocolDescriptor> listProtocols() throws ISLookUpException {
50 33226 michele.ar
		final Map<String, List<ProtocolParameter>> mapParams = Maps.newHashMap();
51 32999 michele.ar
		for (ProtocolDescriptor pd : serviceLocator.getService(CollectorService.class).listProtocols()) {
52
			mapParams.put(pd.getName().trim().toLowerCase(), pd.getParams());
53
		}
54
55 33745 michele.ar
		return Lists.transform(repoUIUtils.fetchVocabularyTerms(protocolsVocabulary), new Function<VocabularyEntry, ProtocolDescriptor>() {
56 32999 michele.ar
57
			@Override
58
			public ProtocolDescriptor apply(final VocabularyEntry e) {
59
				final ProtocolDescriptor pd = new ProtocolDescriptor();
60 33101 michele.ar
				pd.setName(e.getName());
61
				if (mapParams.containsKey(e.getName().toLowerCase().trim())) {
62
					pd.setParams(mapParams.get(e.getName().toLowerCase().trim()));
63 32999 michele.ar
				} else {
64 33226 michele.ar
					pd.setParams(new ArrayList<ProtocolParameter>());
65 32999 michele.ar
				}
66
				return pd;
67
			}
68
69
		});
70
	}
71
72
	public String getDatasourceTypeVocabulary() {
73
		return datasourceTypeVocabulary;
74
	}
75
76
	@Required
77
	public void setDatasourceTypeVocabulary(final String datasourceTypeVocabulary) {
78
		this.datasourceTypeVocabulary = datasourceTypeVocabulary;
79
	}
80
81
	public String getComplianceVocabulary() {
82
		return complianceVocabulary;
83
	}
84
85
	@Required
86
	public void setComplianceVocabulary(final String complianceVocabulary) {
87
		this.complianceVocabulary = complianceVocabulary;
88
	}
89
90
	public String getContentDescriptionsVocabulary() {
91
		return contentDescriptionsVocabulary;
92
	}
93
94
	@Required
95
	public void setContentDescriptionsVocabulary(final String contentDescriptionsVocabulary) {
96
		this.contentDescriptionsVocabulary = contentDescriptionsVocabulary;
97
	}
98
99
	public String getProtocolsVocabulary() {
100
		return protocolsVocabulary;
101
	}
102
103
	@Required
104
	public void setProtocolsVocabulary(final String protocolsVocabulary) {
105
		this.protocolsVocabulary = protocolsVocabulary;
106
	}
107
108
}