Project

General

Profile

« Previous | Next » 

Revision 49898

1. Create new update methods for repository api
2. Rename piwik file.
3. Create bean repomanager.datasource
4. Update converter methods ( typology, datasourceClass )

View differences:

RepositoryApiImpl.java
41 41

  
42 42
    private Map<String, Vocabulary> vocabularyMap = new ConcurrentHashMap<String, Vocabulary>();
43 43

  
44
    private Map<String,String> countriesMap = new HashMap<>();
45
    private Map<String,String> inverseCountriesMap = new HashMap<>();
44 46

  
47

  
45 48
    @PostConstruct
46 49
    private void init(){
47 50
        LOGGER.debug("Initialization method of repository api!");
......
53 56
            vocabularyMap.put(vocName, vocabularyLoader.getVocabulary(vocName, Locale.ENGLISH, Locale.ROOT));
54 57
        }
55 58

  
59
        Country[] countries = getCountries();
60
        for(Country c: countries){
61
            countriesMap.put(c.getName(),c.getCode());
62
            inverseCountriesMap.put(c.getCode(),c.getName());
63
        }
64

  
65

  
56 66
    }
57 67

  
58 68
    @Override
......
109 119

  
110 120
    @Override
111 121
    public List<Repository> getRepositoriesByCountry(@PathVariable("country") String country,
112
                                                     @PathVariable("country") String mode) throws JSONException {
122
                                                     @PathVariable("mode") String mode) throws JSONException {
113 123

  
114 124
        LOGGER.debug("Getting repositories by country!");
115
        int page = 1;
116
        int size = 10;
117
        String countryCode = getCountryCode(country);
125
        int page = 0;
126
        int size = 100;
127

  
128
        String countryCode = countriesMap.get(country);
118 129
        String filterKey = "UNKNOWN";
119 130
        if(mode.equalsIgnoreCase("opendoar")) {
120 131
            filterKey = "openaire____::opendoar";
......
138 149
            List<Repository> rep = Converter.jsonToRepositoryList(new JSONArray(rs));
139 150

  
140 151
            Collection<Repository> repos = this.getRepositoriesByMode(filterKey,rep);
141
            this.addRepos(resultSet,repos);
142
            //resultSet.addAll(repos);
152
            resultSet.addAll(repos);
143 153

  
144 154
            page+=1;
145 155
            uriComponents = UriComponentsBuilder
......
149 159
                    .build().expand(page,size).encode();
150 160
            rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
151 161
        }
162
        for(Repository r : resultSet)
163
            r.setCountryName(getCountryName(r.getCountryCode()));
152 164
        return resultSet;
153 165
    }
154 166

  
155
    private String getCountryCode(String country) {
156 167

  
157
        Country[] countries = getCountries();
158
        for(Country c : countries)
159
            if(c.getName().equals(country))
160
                return c.getCode();
161
        return country;
162
    }
163

  
164
    private void addRepos(List<Repository> resultSet, Collection<Repository> repos) {
165
        for(Repository r : repos)
166
            if(!resultSet.contains(r))
167
                resultSet.add(r);
168
    }
169

  
170 168
    private Collection<Repository> getRepositoriesByMode(String mode, List<Repository> rs) {
171 169

  
172 170
        List<Repository> reps = new ArrayList<>();
......
190 188
                .build().expand(page,size).encode();
191 189
        
192 190
        String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
193
        return Converter.jsonToRepositoryList(new JSONArray(rs));
191
        List<Repository> repos = Converter.jsonToRepositoryList(new JSONArray(rs));
192
        for(Repository r : repos)
193
            r.setCountryName(getCountryName(r.getCountryCode()));
194
        return repos;
194 195
    }
195 196

  
196 197
    @Override
......
202 203
                .build().expand(id).encode();
203 204

  
204 205
        String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
205
        return  Converter.jsonToRepositoryObject(new JSONObject(rs));
206
        Repository repo = Converter.jsonToRepositoryObject(new JSONObject(rs));
207
        if (repo != null)
208
            repo.setCountryName(getCountryName(repo.getCountryCode()));
209
        return repo;
206 210
    }
207 211

  
208 212
    @Override
......
235 239
                .build().expand(page,size).encode();
236 240

  
237 241
        String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
238
        return Converter.jsonToRepositoryList(new JSONArray(rs));
242
        List<Repository> repos = Converter.jsonToRepositoryList(new JSONArray(rs));
243
        for(Repository r : repos)
244
            r.setCountryName(getCountryName(r.getCountryCode()));
245
        return repos;
239 246
    }
240 247

  
241 248
    @Override
......
251 258
    }
252 259

  
253 260
    @Override
254
    public String addRepository(@RequestBody Repository repository) throws JSONException {
261
    public void addRepository(@RequestBody Repository repository) throws JSONException {
262

  
263
        LOGGER.debug("Adding repository with name : " + repository.getOfficialName());
264

  
255 265
        UriComponents uriComponents = UriComponentsBuilder
256 266
                .fromHttpUrl(baseAddress + "/ds/add/")
257 267
                .build()
258 268
                .encode();
259
        return restTemplate.postForObject(uriComponents.toUri(),Converter.repositoryObjectToJson(repository),String.class);
269

  
270
        LOGGER.debug("Repository equals : " + Converter.repositoryObjectToJson(repository));
271
        restTemplate.postForObject(uriComponents.toUri(),Converter.repositoryObjectToJson(repository),String.class);
260 272
    }
261 273

  
262 274
    @Override
......
360 372
    }
361 373

  
362 374
    @Override
375
    public String updateTimezone(@RequestParam(value = "id")   String id,
376
                                 @RequestParam(value = "timezone")  String timezone) {
377
        UriComponents uriComponents = UriComponentsBuilder
378
                .fromHttpUrl(baseAddress + "/ds/update/timezone")
379
                .queryParam("dsId",id)
380
                .queryParam("timezone",timezone)
381
                .build().encode();
382
        return restTemplate.postForObject(uriComponents.toUri(), null,String.class);
383
    }
384

  
385
    @Override
386
    public String updateTypology(@RequestParam(value = "id")   String id,
387
                                 @RequestParam(value = "typology")  String typology) {
388
        UriComponents uriComponents = UriComponentsBuilder
389
                .fromHttpUrl(baseAddress + "/ds/update/typology")
390
                .queryParam("dsId",id)
391
                .queryParam("typology",typology)
392
                .build().encode();
393
        return restTemplate.postForObject(uriComponents.toUri(), null,String.class);
394
    }
395

  
396
    @Override
397
    public String updateLogoUrl(@RequestParam(value = "id")   String id,
398
                                @RequestParam(value = "logoUrl") String logoUrl) {
399
        UriComponents uriComponents = UriComponentsBuilder
400
                .fromHttpUrl(baseAddress + "/ds/update/logourl")
401
                .queryParam("dsId",id)
402
                .queryParam("logourl",logoUrl)
403
                .build().encode();
404
        return restTemplate.postForObject(uriComponents.toUri(), null,String.class);
405
    }
406

  
407
    @Override
363 408
    public List<String> getUrlsOfUserRepos(@PathVariable("user_email") String user_email,
364 409
                                           @PathVariable("page") String page,
365 410
                                           @PathVariable("size") String size) throws JSONException {
......
459 504

  
460 505
    }
461 506

  
507
    @Override
508
    public String getCountryName(String countryCode) {
509
        return inverseCountriesMap.get(countryCode);
510
    }
511

  
462 512
}

Also available in: Unified diff