Project

General

Profile

« Previous | Next » 

Revision 49988

1. Bug fix on broker api.
2. Add update method for platform field.
3. Add json to repositoryInterfaceList method on Converter class.

View differences:

modules/uoa-repository-manager-service/src/main/java/eu/dnetlib/repo/manager/service/utils/Converter.java
96 96
        String countryCode = ((JSONArray)datasource.get("organizations")).getJSONObject(0).get("country").toString();
97 97
        repository.setCountryCode(countryCode);
98 98

  
99

  
100
        String collectedFrom = datasource.get("collectedfrom").toString();
101
        //TODO check data consistency
102
        String type = "UNKNOWN";
103
        if (collectedFrom.equalsIgnoreCase("openaire____::opendoar")) {
104
            type = "opendoar";
105
        } else if (collectedFrom.equalsIgnoreCase("openaire____::re3data")) {
106
            type = "re3data";
107
        } else if (collectedFrom.equalsIgnoreCase("infrastruct_::openaire")) {
108
            type = "journal";
109
        }
110

  
111
        repository.setDatasourceType(type);
112

  
113

  
99 114
        return repository;
100 115
    }
101 116

  
......
139 154
        return resultSet;
140 155
    }
141 156

  
157
    public static List<RepositoryInterface> jsonToRepositoryInterfaceList(JSONArray rs) throws JSONException {
158

  
159
        List<RepositoryInterface> resultSet = new ArrayList<>();
160
        for(int i=0;i<rs.length();i++)
161
            resultSet.add(jsonToRepositoryInterfaceObject( rs.getJSONObject(i)) );
162
        return resultSet;
163
    }
164

  
142 165
    public static RepositoryInterface jsonToRepositoryInterfaceObject(JSONObject repositoryInterfaceObject) throws JSONException {
143 166

  
144 167
        RepositoryInterface repositoryInterface = new RepositoryInterface();
modules/uoa-repository-manager-service/src/main/java/eu/dnetlib/repo/manager/service/controllers/BrokerApiImpl.java
168 168

  
169 169
        int page = 0;
170 170
        int size = 50;
171
        List<Repository> rs = null;
171
        List<Repository> rs ;
172 172
        List<Repository> resultSet = new ArrayList<>();
173 173

  
174 174
        while (true){
175 175
            rs = repoAPI.getRepositoriesOfUser(userEmail, String.valueOf(page), String.valueOf(size));
176
            resultSet.addAll(rs);
177
            page+=1;
176 178
            if(rs.size() == 0) break;
177
            resultSet.addAll(rs);
178 179
        }
179 180
        return resultSet;
180 181
    }
modules/uoa-repository-manager-service/src/main/java/eu/dnetlib/repo/manager/service/controllers/RepositoryApi.java
59 59
    @RequestMapping(value = "/getRepositoryInterface/{id}", method = RequestMethod.GET,
60 60
            produces = MediaType.APPLICATION_JSON_VALUE)
61 61
    @ResponseBody
62
    RepositoryInterface getRepositoyInterface(String id) throws JSONException;
62
    List<RepositoryInterface> getRepositoryInterface(String id) throws JSONException;
63 63

  
64 64
    @RequestMapping(value = "/addRepository", method = RequestMethod.POST,
65 65
            consumes = MediaType.APPLICATION_JSON_VALUE)
......
130 130
    @ResponseBody
131 131
    String updateLogoUrl(String id, String logoUrl);
132 132

  
133
    @RequestMapping(value = "/updatePlatform", method = RequestMethod.POST,
134
            produces = MediaType.APPLICATION_JSON_VALUE)
135
    @ResponseBody
136
    String updatePlatform(String id, String platform);
133 137

  
138

  
134 139
    @RequestMapping(value = "/getUrlsOfUserRepos/{user_email}/{page}/{size}/",method = RequestMethod.GET,
135 140
            produces = MediaType.APPLICATION_JSON_VALUE)
136 141
    @ResponseBody
modules/uoa-repository-manager-service/src/main/java/eu/dnetlib/repo/manager/service/controllers/RepositoryApiImpl.java
194 194

  
195 195
        String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
196 196
        List<Repository> repos = Converter.jsonToRepositoryList(new JSONArray(rs));
197
        for (Repository r : repos)
197
        for (Repository r : repos){
198
         //   r.setInterfaces(this.getRepositoryInterface(r.getId()));
198 199
            r.setCountryName(getCountryName(r.getCountryCode()));
200
        }
201

  
199 202
        return repos;
200 203
    }
201 204

  
......
209 212

  
210 213
        String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
211 214
        Repository repo = Converter.jsonToRepositoryObject(new JSONObject(rs));
215
        //repo.setInterfaces(this.getRepositoryInterface(repo.getId()));
212 216
        if (repo != null)
213 217
            repo.setCountryName(getCountryName(repo.getCountryCode()));
214 218
        return repo;
215 219
    }
216 220

  
221

  
217 222
    @Override
218 223
    public Aggregations getRepositoryAggregations(@PathVariable("id") String id) throws JSONException {
219 224

  
......
251 256

  
252 257
        String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
253 258
        List<Repository> repos = Converter.jsonToRepositoryList(new JSONArray(rs));
254
        for (Repository r : repos)
259
        for (Repository r : repos){
260
           // r.setInterfaces(this.getRepositoryInterface(r.getId()));
255 261
            r.setCountryName(getCountryName(r.getCountryCode()));
262
        }
256 263
        return repos;
257 264
    }
258 265

  
259 266
    @Override
260
    public RepositoryInterface getRepositoyInterface(@PathVariable("id") String id) throws JSONException {
267
    public List<RepositoryInterface> getRepositoryInterface(@PathVariable("id") String id) throws JSONException {
261 268

  
262 269
        UriComponents uriComponents = UriComponentsBuilder
263 270
                .fromHttpUrl(baseAddress + "/ds/api/")
......
265 272
                .build().expand(id).encode();
266 273

  
267 274
        String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
268
        return Converter.jsonToRepositoryInterfaceObject(new JSONArray(rs).getJSONObject(0));
275
        return Converter.jsonToRepositoryInterfaceList(new JSONArray(rs));
269 276
    }
270 277

  
271 278
    @Override
......
480 487
            e = this.getRepositoryById(repoId);
481 488
            iFace = createRepositoryInterface(e,iFace,datatype);
482 489

  
490
            LOGGER.debug("iFace equals : " + Converter.repositoryInterfaceObjectToJson(e,iFace));
491

  
483 492
            UriComponents uriComponents = UriComponentsBuilder
484 493
                    .fromHttpUrl(baseAddress + "/ds/api/add/")
485 494
                    .build()
......
607 616
    }
608 617

  
609 618
    @Override
619
    public String updatePlatform(String id, String platform) {
620
        UriComponents uriComponents = UriComponentsBuilder
621
                .fromHttpUrl(baseAddress + "/ds/platform")
622
                .queryParam("dsId",id)
623
                .queryParam("platform",platform)
624
                .build().encode();
625
        return restTemplate.postForObject(uriComponents.toUri(), null,String.class);
626
    }
627

  
628
    @Override
610 629
    public List<String> getUrlsOfUserRepos(@PathVariable("user_email") String user_email,
611 630
                                           @PathVariable("page") String page,
612 631
                                           @PathVariable("size") String size) throws JSONException {

Also available in: Unified diff