Revision 49397
Added by Panagiotis Kanakakis over 6 years ago
RepositoryApiImpl.java | ||
---|---|---|
13 | 13 |
import org.springframework.web.bind.annotation.PathVariable; |
14 | 14 |
import org.springframework.web.bind.annotation.RequestBody; |
15 | 15 |
import org.springframework.web.bind.annotation.RequestParam; |
16 |
import org.springframework.web.bind.annotation.ResponseBody; |
|
17 | 16 |
import org.springframework.web.client.RestTemplate; |
18 | 17 |
import org.springframework.web.util.UriComponents; |
19 | 18 |
import org.springframework.web.util.UriComponentsBuilder; |
... | ... | |
56 | 55 |
.queryParam("country",country) |
57 | 56 |
.build().expand(page,size).encode(); |
58 | 57 |
|
59 |
RestTemplate template = new RestTemplate(); |
|
60 |
template.getMessageConverters().add(new MappingJackson2HttpMessageConverter()); |
|
61 |
|
|
62 |
String rs = template.getForObject(uriComponents.toUri(), String.class); |
|
58 |
Repository[] rs = restTemplate.getForObject(uriComponents.toUri(), Repository[].class); |
|
63 | 59 |
return Converter.jsonToRepositoryList(new JSONArray(rs)); |
64 | 60 |
} |
65 | 61 |
|
... | ... | |
67 | 63 |
public List<Repository> getRepositoriesOfUser(@PathVariable("userEmail") String userEmail, |
68 | 64 |
@PathVariable("page") String page, |
69 | 65 |
@PathVariable("size") String size) throws JSONException { |
70 |
String vars = page+"/"+size+"?contactemail="+userEmail; |
|
71 |
String uri = baseAddress+ "/ds/search/email/" + vars; |
|
72 |
JSONArray jsonArray = new JSONArray(RestService.executeGET(uri)); |
|
73 |
return Converter.jsonToRepositoryList(jsonArray); |
|
66 |
|
|
67 |
UriComponents uriComponents = UriComponentsBuilder |
|
68 |
.fromHttpUrl(baseAddress + "/ds/search/email/") |
|
69 |
.path("/{page}/{size}/") |
|
70 |
.queryParam("contactemail",userEmail) |
|
71 |
.build().expand(page,size).encode(); |
|
72 |
|
|
73 |
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class); |
|
74 |
return Converter.jsonToRepositoryList(new JSONArray(rs)); |
|
74 | 75 |
} |
75 | 76 |
|
76 | 77 |
@Override |
77 | 78 |
public Repository getRepositoryById(@PathVariable("id") String id) throws JSONException { |
78 |
String uri = baseAddress+ "/ds/get/" + id; |
|
79 |
JSONObject jsonObject = new JSONObject( RestService.executeGET(uri) ); |
|
80 |
return Converter.jsonToRepositoryObject(jsonObject); |
|
79 |
|
|
80 |
UriComponents uriComponents = UriComponentsBuilder |
|
81 |
.fromHttpUrl(baseAddress + "/ds/get/") |
|
82 |
.path("/{id}/") |
|
83 |
.build().expand(id).encode(); |
|
84 |
|
|
85 |
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class); |
|
86 |
return Converter.jsonToRepositoryObject(new JSONObject(rs)); |
|
81 | 87 |
} |
82 | 88 |
|
83 | 89 |
@Override |
84 | 90 |
public List<Repository> getRepositoriesByName(@PathVariable("name") String name, |
85 | 91 |
@PathVariable("page") String page, |
86 | 92 |
@PathVariable("size") String size) throws JSONException { |
87 |
String vars = page+"/"+size+"?name="+name; |
|
88 |
String uri = baseAddress+ "/ds/search/name/" + vars; |
|
89 |
JSONArray jsonArray = new JSONArray(RestService.executeGET(uri)); |
|
90 |
return Converter.jsonToRepositoryList(jsonArray); |
|
93 |
UriComponents uriComponents = UriComponentsBuilder |
|
94 |
.fromHttpUrl(baseAddress + "/ds/search/name/") |
|
95 |
.path("/{page}/{size}") |
|
96 |
.queryParam("name",name) |
|
97 |
.build().expand(page,size).encode(); |
|
98 |
|
|
99 |
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class); |
|
100 |
return Converter.jsonToRepositoryList(new JSONArray(rs)); |
|
91 | 101 |
} |
92 | 102 |
|
93 | 103 |
@Override |
94 | 104 |
public RepositoryInterface getRepositoyInterface(@PathVariable("id") String id) throws JSONException { |
95 |
String uri = baseAddress+ "/ds/service/" + id; |
|
96 |
JSONArray jsonArray = new JSONArray( RestService.executeGET(uri) ); |
|
97 |
return Converter.jsonToRepositoryInterfaceObject(jsonArray.getJSONObject(0)); |
|
105 |
|
|
106 |
UriComponents uriComponents = UriComponentsBuilder |
|
107 |
.fromHttpUrl(baseAddress + "/ds/service/") |
|
108 |
.path("/{id}/") |
|
109 |
.build().expand(id).encode(); |
|
110 |
|
|
111 |
String rs = restTemplate.getForObject(uriComponents.toUri(),String.class); |
|
112 |
return Converter.jsonToRepositoryInterfaceObject(new JSONArray(rs).getJSONObject(0)); |
|
98 | 113 |
} |
99 | 114 |
|
100 | 115 |
@Override |
101 | 116 |
public String addRepository(@RequestBody Repository repository) throws JSONException { |
102 |
String uri = baseAddress+ "/ds/add/"; |
|
103 |
return RestService.executePOST(uri, Converter.repositoryObjectToJson(repository)); |
|
117 |
UriComponents uriComponents = UriComponentsBuilder |
|
118 |
.fromHttpUrl(baseAddress + "/ds/add/") |
|
119 |
.build() |
|
120 |
.encode(); |
|
121 |
return restTemplate.postForObject(uriComponents.toUri(),Converter.repositoryObjectToJson(repository),String.class); |
|
104 | 122 |
} |
105 | 123 |
|
106 | 124 |
@Override |
107 | 125 |
public String addRepositoryInterface(RepositoryInterface repositoryInterface) throws JSONException { |
108 |
String uri = baseAddress+ "/ds/service/add/"; |
|
109 |
return RestService.executePOST(uri, Converter.repositoryInterfaceObjectToJson(repositoryInterface)); |
|
126 |
UriComponents uriComponents = UriComponentsBuilder |
|
127 |
.fromHttpUrl(baseAddress + "/ds/service/add/") |
|
128 |
.build() |
|
129 |
.encode(); |
|
130 |
return restTemplate.postForObject(uriComponents.toUri(), Converter.repositoryInterfaceObjectToJson(repositoryInterface),String.class); |
|
110 | 131 |
} |
111 | 132 |
|
112 | 133 |
@Override |
... | ... | |
116 | 137 |
|
117 | 138 |
@Override |
118 | 139 |
public List<String> getTypologies() { |
119 |
System.out.println("Typologies"); |
|
120 | 140 |
return Converter.readFile("typologies.txt"); |
121 | 141 |
} |
122 | 142 |
|
... | ... | |
128 | 148 |
@Override |
129 | 149 |
public String updateManagedStatus(@RequestParam(value = "id") String id, |
130 | 150 |
@RequestParam(value = "managed") String managed) { |
131 |
String uri = baseAddress+ "/ds/manage?id="+id+"&managed="+managed; |
|
132 |
return RestService.executePOST(uri,null); |
|
151 |
|
|
152 |
UriComponents uriComponents = UriComponentsBuilder |
|
153 |
.fromHttpUrl(baseAddress + "/ds/manage/") |
|
154 |
.queryParam("id",id) |
|
155 |
.queryParam("managed",managed) |
|
156 |
.build().encode(); |
|
157 |
|
|
158 |
return restTemplate.postForObject(uriComponents.toUri(), null,String.class); |
|
133 | 159 |
} |
134 | 160 |
|
135 | 161 |
@Override |
136 | 162 |
public String updateEnglishName(@RequestParam(value = "id") String id, |
137 | 163 |
@RequestParam(value = "englishname") String englishName) { |
138 |
String uri = baseAddress+ "/ds/manage?dsId="+id+"&englishname="+englishName; |
|
139 |
return RestService.executePOST(uri,null); |
|
164 |
|
|
165 |
UriComponents uriComponents = UriComponentsBuilder |
|
166 |
.fromHttpUrl(baseAddress + "/ds/manage/") |
|
167 |
.queryParam("dsId",id) |
|
168 |
.queryParam("englishname",englishName) |
|
169 |
.build().encode(); |
|
170 |
return restTemplate.postForObject(uriComponents.toUri(), null,String.class); |
|
171 |
|
|
172 |
|
|
140 | 173 |
} |
141 | 174 |
|
142 | 175 |
@Override |
143 | 176 |
public String updateLatitude(@RequestParam(value = "id") String id, |
144 | 177 |
@RequestParam(value = "managed") String latitude) { |
145 |
String uri = baseAddress+ "/ds/manage?dsId="+id+"&latitude="+latitude; |
|
146 |
return RestService.executePOST(uri,null); |
|
178 |
|
|
179 |
UriComponents uriComponents = UriComponentsBuilder |
|
180 |
.fromHttpUrl(baseAddress + "/ds/manage/") |
|
181 |
.queryParam("dsId",id) |
|
182 |
.queryParam("latitude",latitude) |
|
183 |
.build().encode(); |
|
184 |
return restTemplate.postForObject(uriComponents.toUri(), null,String.class); |
|
147 | 185 |
} |
148 | 186 |
|
149 | 187 |
@Override |
150 | 188 |
public String updateLongitude(@RequestParam(value = "id") String id, |
151 | 189 |
@RequestParam(value = "longitude") String longitude) { |
152 |
String uri = baseAddress+ "/ds/manage?dsId="+id+"&longitude="+longitude; |
|
153 |
return RestService.executePOST(uri,null); |
|
190 |
|
|
191 |
UriComponents uriComponents = UriComponentsBuilder |
|
192 |
.fromHttpUrl(baseAddress + "/ds/manage/") |
|
193 |
.queryParam("dsId",id) |
|
194 |
.queryParam("longitude",longitude) |
|
195 |
.build().encode(); |
|
196 |
return restTemplate.postForObject(uriComponents.toUri(), null,String.class); |
|
154 | 197 |
} |
155 | 198 |
|
156 | 199 |
@Override |
157 | 200 |
public String updateOfficialName(@RequestParam(value = "id") String id, |
158 | 201 |
@RequestParam(value = "officialname") String officialname) { |
159 |
String uri = baseAddress+ "/ds/manage?dsId="+id+"&officialname="+officialname; |
|
160 |
return RestService.executePOST(uri,null); |
|
202 |
|
|
203 |
UriComponents uriComponents = UriComponentsBuilder |
|
204 |
.fromHttpUrl(baseAddress + "/ds/manage/") |
|
205 |
.queryParam("dsId",id) |
|
206 |
.queryParam("officialname",officialname) |
|
207 |
.build().encode(); |
|
208 |
return restTemplate.postForObject(uriComponents.toUri(), null,String.class); |
|
161 | 209 |
} |
162 | 210 |
|
163 | 211 |
@Override |
Also available in: Unified diff
Uri components builder