1 |
49362
|
panagiotis
|
package eu.dnetlib.repo.manager.service.controllers;
|
2 |
49236
|
panagiotis
|
|
3 |
|
|
import eu.dnetlib.repo.manager.service.utils.Converter;
|
4 |
|
|
import eu.dnetlib.domain.data.Repository;
|
5 |
|
|
import eu.dnetlib.domain.data.RepositoryInterface;
|
6 |
|
|
import org.json.JSONArray;
|
7 |
49362
|
panagiotis
|
import org.json.JSONException;
|
8 |
49236
|
panagiotis
|
import org.json.JSONObject;
|
9 |
|
|
import org.springframework.beans.factory.annotation.Value;
|
10 |
49245
|
panagiotis
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
11 |
49236
|
panagiotis
|
import org.springframework.stereotype.Component;
|
12 |
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
13 |
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
14 |
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
15 |
49245
|
panagiotis
|
import org.springframework.web.client.RestTemplate;
|
16 |
49304
|
panagiotis
|
import org.springframework.web.util.UriComponents;
|
17 |
49245
|
panagiotis
|
import org.springframework.web.util.UriComponentsBuilder;
|
18 |
|
|
|
19 |
49304
|
panagiotis
|
import javax.annotation.PostConstruct;
|
20 |
49236
|
panagiotis
|
import java.util.List;
|
21 |
|
|
|
22 |
|
|
|
23 |
|
|
@Component
|
24 |
|
|
public class RepositoryApiImpl implements RepositoryApi {
|
25 |
|
|
|
26 |
49304
|
panagiotis
|
@Value("${api.baseAddress}")
|
27 |
49236
|
panagiotis
|
private String baseAddress;
|
28 |
|
|
|
29 |
49304
|
panagiotis
|
private RestTemplate restTemplate = null;
|
30 |
|
|
|
31 |
|
|
@PostConstruct
|
32 |
|
|
private void init(){
|
33 |
|
|
restTemplate = new RestTemplate();
|
34 |
|
|
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
|
35 |
|
|
}
|
36 |
|
|
|
37 |
49236
|
panagiotis
|
@Override
|
38 |
|
|
public String getCountries() {
|
39 |
49304
|
panagiotis
|
UriComponents uriComponents = UriComponentsBuilder
|
40 |
|
|
.fromHttpUrl(baseAddress + "/ds/countries")
|
41 |
|
|
.build().encode();
|
42 |
|
|
return restTemplate.getForObject(uriComponents.toUri(), String.class);
|
43 |
49236
|
panagiotis
|
}
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
@Override
|
47 |
|
|
public List<Repository> getRepositoriesByCountry(@PathVariable("country") String country,
|
48 |
|
|
@PathVariable("page") String page,
|
49 |
49362
|
panagiotis
|
@PathVariable("size") String size) throws JSONException {
|
50 |
49245
|
panagiotis
|
/* String vars = page+"/"+size+"?country="+country;
|
51 |
49236
|
panagiotis
|
String uri = baseAddress+ "/ds/search/country/" + vars;
|
52 |
|
|
JSONArray jsonArray = new JSONArray(RestService.executeGET(uri));
|
53 |
49245
|
panagiotis
|
return Converter.jsonToRepositoryList(jsonArray);*/
|
54 |
|
|
|
55 |
49304
|
panagiotis
|
UriComponents uriComponents = UriComponentsBuilder
|
56 |
|
|
.fromHttpUrl(baseAddress + "/ds/search/country/")
|
57 |
|
|
.path("/{page}/{size}/")
|
58 |
|
|
.queryParam("country",country)
|
59 |
|
|
.build().expand(page,size).encode();
|
60 |
49245
|
panagiotis
|
|
61 |
|
|
RestTemplate template = new RestTemplate();
|
62 |
|
|
template.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
|
63 |
|
|
|
64 |
49304
|
panagiotis
|
String rs = template.getForObject(uriComponents.toUri(), String.class);
|
65 |
|
|
return Converter.jsonToRepositoryList(new JSONArray(rs));
|
66 |
49236
|
panagiotis
|
}
|
67 |
|
|
|
68 |
|
|
@Override
|
69 |
|
|
public List<Repository> getRepositoriesOfUser(@PathVariable("userEmail") String userEmail,
|
70 |
|
|
@PathVariable("page") String page,
|
71 |
49362
|
panagiotis
|
@PathVariable("size") String size) throws JSONException {
|
72 |
49236
|
panagiotis
|
String vars = page+"/"+size+"?contactemail="+userEmail;
|
73 |
|
|
String uri = baseAddress+ "/ds/search/email/" + vars;
|
74 |
|
|
JSONArray jsonArray = new JSONArray(RestService.executeGET(uri));
|
75 |
|
|
return Converter.jsonToRepositoryList(jsonArray);
|
76 |
|
|
}
|
77 |
|
|
|
78 |
|
|
@Override
|
79 |
49362
|
panagiotis
|
public Repository getRepositoryById(@PathVariable("id") String id) throws JSONException {
|
80 |
49236
|
panagiotis
|
String uri = baseAddress+ "/ds/get/" + id;
|
81 |
|
|
JSONObject jsonObject = new JSONObject( RestService.executeGET(uri) );
|
82 |
|
|
return Converter.jsonToRepositoryObject(jsonObject);
|
83 |
|
|
}
|
84 |
|
|
|
85 |
|
|
@Override
|
86 |
|
|
public List<Repository> getRepositoriesByName(@PathVariable("name") String name,
|
87 |
|
|
@PathVariable("page") String page,
|
88 |
49362
|
panagiotis
|
@PathVariable("size") String size) throws JSONException {
|
89 |
49236
|
panagiotis
|
String vars = page+"/"+size+"?name="+name;
|
90 |
|
|
String uri = baseAddress+ "/ds/search/name/" + vars;
|
91 |
|
|
JSONArray jsonArray = new JSONArray(RestService.executeGET(uri));
|
92 |
|
|
return Converter.jsonToRepositoryList(jsonArray);
|
93 |
|
|
}
|
94 |
|
|
|
95 |
|
|
@Override
|
96 |
49362
|
panagiotis
|
public RepositoryInterface getRepositoyInterface(@PathVariable("id") String id) throws JSONException {
|
97 |
49236
|
panagiotis
|
String uri = baseAddress+ "/ds/service/" + id;
|
98 |
|
|
JSONArray jsonArray = new JSONArray( RestService.executeGET(uri) );
|
99 |
|
|
return Converter.jsonToRepositoryInterfaceObject(jsonArray.getJSONObject(0));
|
100 |
|
|
}
|
101 |
|
|
|
102 |
|
|
@Override
|
103 |
49362
|
panagiotis
|
public String addRepository(@RequestBody Repository repository) throws JSONException {
|
104 |
49236
|
panagiotis
|
String uri = baseAddress+ "/ds/add/";
|
105 |
|
|
return RestService.executePOST(uri, Converter.repositoryObjectToJson(repository));
|
106 |
|
|
}
|
107 |
|
|
|
108 |
|
|
@Override
|
109 |
49362
|
panagiotis
|
public String addRepositoryInterface(RepositoryInterface repositoryInterface) throws JSONException {
|
110 |
49236
|
panagiotis
|
String uri = baseAddress+ "/ds/service/add/";
|
111 |
|
|
return RestService.executePOST(uri, Converter.repositoryInterfaceObjectToJson(repositoryInterface));
|
112 |
|
|
}
|
113 |
|
|
|
114 |
|
|
@Override
|
115 |
|
|
public List<String> getDnetCountries() {
|
116 |
|
|
return Converter.readFile("countries.txt");
|
117 |
|
|
}
|
118 |
|
|
|
119 |
|
|
@Override
|
120 |
|
|
public List<String> getTypologies() {
|
121 |
49304
|
panagiotis
|
System.out.println("Typologies");
|
122 |
49236
|
panagiotis
|
return Converter.readFile("typologies.txt");
|
123 |
|
|
}
|
124 |
|
|
|
125 |
|
|
@Override
|
126 |
|
|
public List<String> getTimezones() {
|
127 |
|
|
return Converter.readFile("timezones.txt");
|
128 |
|
|
}
|
129 |
|
|
|
130 |
|
|
@Override
|
131 |
|
|
public String updateManagedStatus(@RequestParam(value = "id") String id,
|
132 |
|
|
@RequestParam(value = "managed") String managed) {
|
133 |
|
|
String uri = baseAddress+ "/ds/manage?id="+id+"&managed="+managed;
|
134 |
|
|
return RestService.executePOST(uri,null);
|
135 |
|
|
}
|
136 |
|
|
|
137 |
|
|
@Override
|
138 |
|
|
public String updateEnglishName(@RequestParam(value = "id") String id,
|
139 |
|
|
@RequestParam(value = "englishname") String englishName) {
|
140 |
|
|
String uri = baseAddress+ "/ds/manage?dsId="+id+"&englishname="+englishName;
|
141 |
|
|
return RestService.executePOST(uri,null);
|
142 |
|
|
}
|
143 |
|
|
|
144 |
|
|
@Override
|
145 |
|
|
public String updateLatitude(@RequestParam(value = "id") String id,
|
146 |
|
|
@RequestParam(value = "managed") String latitude) {
|
147 |
|
|
String uri = baseAddress+ "/ds/manage?dsId="+id+"&latitude="+latitude;
|
148 |
|
|
return RestService.executePOST(uri,null);
|
149 |
|
|
}
|
150 |
|
|
|
151 |
|
|
@Override
|
152 |
|
|
public String updateLongitude(@RequestParam(value = "id") String id,
|
153 |
|
|
@RequestParam(value = "longitude") String longitude) {
|
154 |
|
|
String uri = baseAddress+ "/ds/manage?dsId="+id+"&longitude="+longitude;
|
155 |
|
|
return RestService.executePOST(uri,null);
|
156 |
|
|
}
|
157 |
|
|
|
158 |
|
|
@Override
|
159 |
|
|
public String updateOfficialName(@RequestParam(value = "id") String id,
|
160 |
|
|
@RequestParam(value = "officialname") String officialname) {
|
161 |
|
|
String uri = baseAddress+ "/ds/manage?dsId="+id+"&officialname="+officialname;
|
162 |
|
|
return RestService.executePOST(uri,null);
|
163 |
|
|
}
|
164 |
|
|
|
165 |
|
|
@Override
|
166 |
|
|
public String getUrlsOfUserRepos(@PathVariable("user_email") String user_email) {
|
167 |
|
|
|
168 |
|
|
//TODO create service a join datasource d for user u method
|
169 |
|
|
|
170 |
|
|
return null;
|
171 |
|
|
}
|
172 |
|
|
|
173 |
|
|
|
174 |
|
|
}
|