Project

General

Profile

« Previous | Next » 

Revision 50862

Moving branch folders to trunk.

View differences:

RepositoryApiImpl.java
1 1
package eu.dnetlib.repo.manager.service.controllers;
2 2

  
3
import com.fasterxml.jackson.core.JsonProcessingException;
4 3
import com.fasterxml.jackson.databind.DeserializationFeature;
5 4
import com.fasterxml.jackson.databind.ObjectMapper;
6 5
import eu.dnetlib.domain.data.Repository;
7 6
import eu.dnetlib.domain.data.RepositoryInterface;
8 7
import eu.dnetlib.domain.enabling.Vocabulary;
9 8
import eu.dnetlib.repo.manager.service.utils.Converter;
10
import eu.dnetlib.repo.manager.service.utils.RequestFilter;
11 9
import eu.dnetlib.repo.manager.shared.*;
12 10
import gr.uoa.di.driver.enabling.vocabulary.VocabularyLoader;
13 11
import org.apache.commons.codec.digest.DigestUtils;
......
18 16
import org.springframework.beans.factory.annotation.Autowired;
19 17
import org.springframework.beans.factory.annotation.Value;
20 18
import org.springframework.core.ParameterizedTypeReference;
21
import org.springframework.http.*;
19
import org.springframework.http.HttpEntity;
20
import org.springframework.http.HttpHeaders;
21
import org.springframework.http.HttpMethod;
22
import org.springframework.http.ResponseEntity;
22 23
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
23 24
import org.springframework.stereotype.Component;
24 25
import org.springframework.web.bind.annotation.PathVariable;
......
30 31
import org.springframework.web.util.UriComponentsBuilder;
31 32

  
32 33
import javax.annotation.PostConstruct;
34
import javax.ws.rs.QueryParam;
33 35
import java.sql.Timestamp;
34 36
import java.text.Normalizer;
35 37
import java.util.*;
......
150 152
        LOGGER.debug("Getting repositories by country!");
151 153
        int page = 0;
152 154
        int size = 100;
153
        List<Repository> resultSet = new ArrayList<>();
154 155

  
155 156
        String countryCode = countriesMap.get(country);
156 157
        String filterKey = "UNKNOWN";
......
164 165

  
165 166
        LOGGER.debug("Country code equals : " + countryCode);
166 167
        LOGGER.debug("Filter mode equals : " + filterKey);
167
        UriComponents uriComponents = searchDatasource(String.valueOf(page),String.valueOf(size));
168
        RequestFilter requestFilter = new RequestFilter();
169
        requestFilter.setCountry(countryCode);
168
        UriComponents uriComponents = UriComponentsBuilder
169
                .fromHttpUrl(baseAddress + "/ds/search/country/")
170
                .path("/{page}/{size}/")
171
                .queryParam("country", countryCode)
172
                .queryParam("managed", managed)
173
                .build().expand(page, size).encode();
170 174

  
171
        String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class);
175
        String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
172 176
        JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
177

  
178
        List<Repository> resultSet = new ArrayList<>();
173 179
        while (jsonArray.length() > 0 ) {
174 180
            List<Repository> rep = Converter.jsonToRepositoryList(new JSONObject(rs));
175 181

  
......
177 183
            resultSet.addAll(repos);
178 184

  
179 185
            page += 1;
180
            uriComponents = searchDatasource(String.valueOf(page),String.valueOf(size));
181
            
182
            rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class);
186
            uriComponents = UriComponentsBuilder
187
                    .fromHttpUrl(baseAddress + "/ds/search/country/")
188
                    .path("/{page}/{size}/")
189
                    .queryParam("country", countryCode)
190
                    .queryParam("managed", managed)
191
                    .build().expand(page, size).encode();
192
            rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
183 193
            jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
184 194
        }
185 195
        for (Repository r : resultSet)
......
199 209

  
200 210
        List<Repository> reps = new ArrayList<>();
201 211
        for (Repository r : rs) {
202
            if (r.getCollectedFrom() != null && r.getCollectedFrom().equals(mode))
212
            if (r.getCollectedFrom().equals(mode))
203 213
                reps.add(r);
204 214
        }
205 215
        return reps;
......
211 221
                                                  @PathVariable("size") String size) throws JSONException {
212 222

  
213 223
        LOGGER.debug("Retreiving repositories of user : " + userEmail );
214
        UriComponents uriComponents = searchDatasource(page,size);
215
        RequestFilter requestFilter = new RequestFilter();
216
        requestFilter.setRegisteredby(userEmail);
217
        String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class);
224
        UriComponents uriComponents = UriComponentsBuilder
225
                .fromHttpUrl(baseAddress + "/ds/search/registeredby/")
226
                .path("/{page}/{size}/")
227
                .queryParam("registeredBy", userEmail)
228
                .build().expand(page, size).encode();
218 229

  
230
        String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
219 231
        List<Repository> repos = Converter.jsonToRepositoryList(new JSONObject(rs));
220 232
        for (Repository r : repos)
221 233
            this.getRepositoryInfo(r);
......
226 238
    @Override
227 239
    public Repository getRepositoryById(@PathVariable("id") String id) throws JSONException {
228 240

  
229
        LOGGER.debug("Retreiving repositories with id : " + id );
230
        UriComponents uriComponents = searchDatasource("0","100");
231
        RequestFilter requestFilter = new RequestFilter();
232
        requestFilter.setId(id);
233
        String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class);
234
        JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
235
        Repository repo = Converter.jsonToRepositoryObject(jsonArray.getJSONObject(0));
241
        UriComponents uriComponents = UriComponentsBuilder
242
                .fromHttpUrl(baseAddress + "/ds/get/")
243
                .path("/{id}/")
244
                .build().expand(id).encode();
245

  
246
        String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
247
        Repository repo = Converter.jsonToRepositoryObject(new JSONObject(rs));
236 248
        if (repo != null)
237 249
            getRepositoryInfo(repo);
238 250
        return repo;
......
242 254
    @Override
243 255
    public Aggregations getRepositoryAggregations(@PathVariable("id") String id) throws JSONException {
244 256

  
245
        LOGGER.debug("Retreiving aggregations for repository with id : " + id );
246
        UriComponents uriComponents = searchDatasource("0","100");
247
        RequestFilter requestFilter = new RequestFilter();
248
        requestFilter.setId(id);
249
        String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class);
257
        UriComponents uriComponents = UriComponentsBuilder
258
                .fromHttpUrl(baseAddress + "/ds/get/")
259
                .path("/{id}/")
260
                .build().expand(id).encode();
261

  
262
        String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
250 263
        JSONObject repository = new JSONObject(rs);
251 264

  
252 265
        Aggregations aggregations = new Aggregations();
253 266

  
254 267
        try {
255
            LOGGER.debug(repository.getJSONArray("datasourceInfo").getJSONObject(0));
256
            aggregations.setAggregationHistory(Converter.getAggregationHistoryFromJson(repository.getJSONArray("datasourceInfo").getJSONObject(0)));
257
            aggregations.setLastCollection(Converter.getLastCollectionFromJson(repository.getJSONArray("datasourceInfo").getJSONObject(0)));
258
            aggregations.setLastTransformation(Converter.getLastTransformationFromJson(repository.getJSONArray("datasourceInfo").getJSONObject(0)));
268
            aggregations.setAggregationHistory(Converter.getAggregationHistoryFromJson(repository));
269
            aggregations.setLastCollection(Converter.getLastCollectionFromJson(repository));
270
            aggregations.setLastTransformation(Converter.getLastTransformationFromJson(repository));
259 271
            return aggregations;
260 272
        } catch (JSONException e) {
261 273
            LOGGER.debug("JSON aggregation exception ", e);
......
268 280
    public List<Repository> getRepositoriesByName(@PathVariable("name") String name,
269 281
                                                  @PathVariable("page") String page,
270 282
                                                  @PathVariable("size") String size) throws JSONException {
283
        UriComponents uriComponents = UriComponentsBuilder
284
                .fromHttpUrl(baseAddress + "/ds/search/name/")
285
                .path("/{page}/{size}")
286
                .queryParam("name", name)
287
                .build().expand(page, size).encode();
271 288

  
272
        LOGGER.debug("Retreiving  repositories with official name : " + name );
273
        UriComponents uriComponents = searchDatasource("0","100");
274
        RequestFilter requestFilter = new RequestFilter();
275
        requestFilter.setOfficialname(name);
276
        String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class);
277

  
289
        String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
278 290
        List<Repository> repos = Converter.jsonToRepositoryList(new JSONObject(rs));
279 291
        for (Repository r : repos)
280 292
            getRepositoryInfo(r);
......
290 302
                .build().expand(id).encode();
291 303

  
292 304
        String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
293
        return Converter.jsonToRepositoryInterfaceList(new JSONObject(rs));
305
        return Converter.jsonToRepositoryInterfaceList(new JSONArray(rs));
294 306
    }
295 307

  
296 308
    @Override
......
350 362

  
351 363
    private void updateRepository(Repository repository) {
352 364
        this.updateRegisteredByValue(repository.getId(),repository.getRegisteredBy());
353
        this.updateEnglishName(repository.getId(),repository.getOfficialName(),repository.getEnglishName());
365
        this.updateEnglishName(repository.getId(),repository.getEnglishName());
354 366
        this.updateLogoUrl(repository.getId(),repository.getLogoUrl());
355 367
        this.updateTimezone(repository.getId(), String.valueOf(repository.getTimezone()));
356 368
        //TODO update datasource type
......
563 575

  
564 576
    @Override
565 577
    public String updateEnglishName(@RequestParam(value = "id")   String id,
566
                                    @RequestParam(value = "officialName")   String officialName,
567 578
                                    @RequestParam(value = "englishname")  String englishName) {
568 579

  
569 580
        UriComponents uriComponents = UriComponentsBuilder
570
                .fromHttpUrl(baseAddress + "/ds/name/")
581
                .fromHttpUrl(baseAddress + "/ds/englishname/")
571 582
                .queryParam("dsId",id)
572
                .queryParam("officialname",officialName)
573 583
                .queryParam("englishname",englishName)
574 584
                .build().encode();
575 585
        return restTemplate.postForObject(uriComponents.toUri(), null,String.class);
......
657 667
    }
658 668

  
659 669
    @Override
660
    public List<String> getUrlsOfUserRepos(@PathVariable("user_email") String userEmail,
670
    public List<String> getUrlsOfUserRepos(@PathVariable("user_email") String user_email,
661 671
                                           @PathVariable("page") String page,
662 672
                                           @PathVariable("size") String size) throws JSONException {
663 673
        UriComponents uriComponents = UriComponentsBuilder
664 674
                .fromHttpUrl(baseAddress + "/api/baseurl/")
665 675
                .path("/{page}/{size}")
676
                .queryParam("userEmail",user_email)
666 677
                .build().expand(page,size).encode();
667

  
668

  
669
        RequestFilter requestFilter = new RequestFilter();
670
        requestFilter.setRegisteredby(userEmail);
671
        return Arrays.asList(restTemplate.postForObject(uriComponents.toUri(),requestFilter, String[].class));
678
        return Arrays.asList(restTemplate.getForObject(uriComponents.toUri(), String[].class));
672 679
    }
673 680

  
674 681
    @Override
......
813 820
        return null;
814 821
    }
815 822

  
816
    private UriComponents searchDatasource(String page,String size){
817 823

  
818
        return UriComponentsBuilder
819
                .fromHttpUrl(baseAddress + "/ds/search/")
820
                .path("/{page}/{size}/")
821
                .queryParam("requestSortBy","id")
822
                .queryParam("order","ASCENDING")
823
                .build().expand(page, size).encode();
824
    }
825

  
826

  
827 824
}

Also available in: Unified diff