Project

General

Profile

« Previous | Next » 

Revision 50219

1. Changes on piwik api
2. Changes on repository interface (new response entities)
3. Changes on converter class due to new json response.

View differences:

RepositoryApiImpl.java
29 29
import org.springframework.web.util.UriComponentsBuilder;
30 30

  
31 31
import javax.annotation.PostConstruct;
32
import javax.ws.rs.Path;
33 32
import javax.ws.rs.QueryParam;
34
import java.io.IOException;
35 33
import java.sql.Timestamp;
36 34
import java.text.Normalizer;
37 35
import java.util.*;
......
54 52
    @Autowired
55 53
    private VocabularyLoader vocabularyLoader;
56 54

  
55
    @Autowired
56
    private PiWikApi piWikApi;
57

  
57 58
    private Map<String, Vocabulary> vocabularyMap = new ConcurrentHashMap<String, Vocabulary>();
58 59

  
59 60
    private Map<String, String> countriesMap = new HashMap<>();
......
137 138

  
138 139
    @Override
139 140
    public List<Repository> getRepositoriesByCountry(@PathVariable("country") String country,
140
                                                     @PathVariable("mode") String mode) throws JSONException {
141
                                                     @PathVariable("mode") String mode,
142
                                                     @RequestParam(value = "managed",required=false) Boolean managed) throws JSONException {
141 143

  
142 144
        LOGGER.debug("Getting repositories by country!");
143 145
        int page = 0;
......
159 161
                .fromHttpUrl(baseAddress + "/ds/search/country/")
160 162
                .path("/{page}/{size}/")
161 163
                .queryParam("country", countryCode)
164
                .queryParam("managed", managed)
162 165
                .build().expand(page, size).encode();
163 166

  
164 167
        String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
168
        JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
169

  
165 170
        List<Repository> resultSet = new ArrayList<>();
166
        while (!rs.equals("[]")) {
167
            List<Repository> rep = Converter.jsonToRepositoryList(new JSONArray(rs));
171
        while (jsonArray.length() > 0 ) {
172
            List<Repository> rep = Converter.jsonToRepositoryList(new JSONObject(rs));
168 173

  
169 174
            Collection<Repository> repos = this.getRepositoriesByMode(filterKey, rep);
170 175
            resultSet.addAll(repos);
......
174 179
                    .fromHttpUrl(baseAddress + "/ds/search/country/")
175 180
                    .path("/{page}/{size}/")
176 181
                    .queryParam("country", countryCode)
182
                    .queryParam("managed", managed)
177 183
                    .build().expand(page, size).encode();
178 184
            rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
185
            jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
179 186
        }
180
        for (Repository r : resultSet){
181
            r.setInterfaces(this.getRepositoryInterface(r.getId()));
182
            r.setCountryName(getCountryName(r.getCountryCode()));
183
        }
187
        for (Repository r : resultSet)
188
            this.getRepositoryInfo(r);
184 189

  
185 190
        return resultSet;
186 191
    }
187 192

  
193
    private void getRepositoryInfo(Repository r) throws JSONException {
194
        r.setInterfaces(this.getRepositoryInterface(r.getId()));
195
        r.setPiwikInfo(piWikApi.getPiwikSiteForRepo(r.getId()));
196
        r.setCountryName(getCountryName(r.getCountryCode()));
197
    }
188 198

  
199

  
189 200
    private Collection<Repository> getRepositoriesByMode(String mode, List<Repository> rs) {
190 201

  
191 202
        List<Repository> reps = new ArrayList<>();
......
209 220
                .build().expand(page, size).encode();
210 221

  
211 222
        String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
212
        List<Repository> repos = Converter.jsonToRepositoryList(new JSONArray(rs));
213
        for (Repository r : repos){
214
            r.setInterfaces(this.getRepositoryInterface(r.getId()));
215
            r.setCountryName(getCountryName(r.getCountryCode()));
216
        }
223
        List<Repository> repos = Converter.jsonToRepositoryList(new JSONObject(rs));
224
        for (Repository r : repos)
225
            this.getRepositoryInfo(r);
217 226

  
218 227
        return repos;
219 228
    }
......
228 237

  
229 238
        String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
230 239
        Repository repo = Converter.jsonToRepositoryObject(new JSONObject(rs));
231
        if (repo != null) {
232
            repo.setCountryName(getCountryName(repo.getCountryCode()));
233
            repo.setInterfaces(this.getRepositoryInterface(repo.getId()));
234
        }
240
        if (repo != null)
241
            getRepositoryInfo(repo);
235 242
        return repo;
236 243
    }
237 244

  
......
272 279
                .build().expand(page, size).encode();
273 280

  
274 281
        String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
275
        List<Repository> repos = Converter.jsonToRepositoryList(new JSONArray(rs));
276
        for (Repository r : repos){
277
           // r.setInterfaces(this.getRepositoryInterface(r.getId()));
278
            r.setCountryName(getCountryName(r.getCountryCode()));
279
        }
282
        List<Repository> repos = Converter.jsonToRepositoryList(new JSONObject(rs));
283
        for (Repository r : repos)
284
            getRepositoryInfo(r);
280 285
        return repos;
281 286
    }
282 287

  

Also available in: Unified diff