Project

General

Profile

« Previous | Next » 

Revision 49790

1. Create method to convert country names -> country codes
2. Create methods for : getDatasourceClasses , getCompatibilityClasses

View differences:

modules/uoa-repository-manager-service/src/main/java/eu/dnetlib/repo/manager/service/utils/Converter.java
192 192
        String line;
193 193
        ArrayList<String> list = new ArrayList<String>();
194 194
        try {
195
            InputStream in = Converter.class.getResourceAsStream("resources/eu/dnetlib/repo/manager/service/utils/"+filename);
195
            //InputStream in = Converter.class.getResourceAsStream("resources/eu/dnetlib/repo/manager/service/utils/"+filename);
196
            InputStream in = Converter.class.getClass().getResourceAsStream(filename);
196 197
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
197 198
            while((line = br.readLine()) != null) {
198 199
                list.add(line.trim());
modules/uoa-repository-manager-service/src/main/java/eu/dnetlib/repo/manager/service/controllers/RepositoryApi.java
10 10
import org.springframework.web.bind.annotation.ResponseBody;
11 11
import org.springframework.web.bind.annotation.RestController;
12 12
import java.util.List;
13
import java.util.Set;
13
import java.util.Map;
14 14

  
15 15
@RestController
16 16
@RequestMapping(value = "/repository")
......
29 29
    @RequestMapping(value = "/getRepositoriesByCountry/{country}", method = RequestMethod.GET,
30 30
            produces = MediaType.APPLICATION_JSON_VALUE)
31 31
    @ResponseBody
32
    Set<String> getRepositoriesByCountry(String country) throws JSONException;
32
    List<Repository> getRepositoriesByCountry(String country,String mode) throws JSONException;
33 33

  
34 34
    @RequestMapping(value = "/getRepositoriesOfUser/{userEmail}/{page}/{size}")
35 35
    @ResponseBody
......
123 123
    @ResponseBody
124 124
    List<String> getDatasourceVocabularies(String mode);
125 125

  
126
    @RequestMapping(value = "/getCompatibilityClasses/{mode}",method = RequestMethod.GET,
127
            produces = MediaType.APPLICATION_JSON_VALUE)
128
    @ResponseBody
129
    Map<String, String> getCompatibilityClasses(String mode);
126 130

  
131
    @RequestMapping(value = "/getDatasourceClasses/{mode}",method = RequestMethod.GET,
132
            produces = MediaType.APPLICATION_JSON_VALUE)
133
    @ResponseBody
134
    Map<String, String> getDatasourceClasses(String mode);
127 135

  
128 136

  
129 137

  
130

  
131

  
132 138
}
modules/uoa-repository-manager-service/src/main/java/eu/dnetlib/repo/manager/service/controllers/RepositoryApiImpl.java
108 108

  
109 109

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

  
113

  
114
        LOGGER.debug("Getting repositories by country!");
114 115
        int page = 1;
115 116
        int size = 10;
116
        String mode = "openaire____::opendoar";
117
        String countryCode = getCountryCode(country);
117 118

  
119

  
120
        LOGGER.debug("Country code equals : " + countryCode);
118 121
        UriComponents uriComponents = UriComponentsBuilder
119 122
                                            .fromHttpUrl(baseAddress + "/ds/search/country/")
120 123
                                            .path("/{page}/{size}/")
......
122 125
                                            .build().expand(page,size).encode();
123 126

  
124 127
        String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
125
        Set<String> resultSet = new HashSet<>();
128
        List<Repository> resultSet = new ArrayList<>();
126 129
        while(!rs.equals("[]")){
127 130
            List<Repository> rep = Converter.jsonToRepositoryList(new JSONArray(rs));
128 131

  
129
            Collection<String> repos = this.getRepositoriesByMode(mode,rep);
130
            this.addRepos(resultSet,repos);
131
            
132
            Collection<Repository> repos = this.getRepositoriesByMode(mode,rep);
133
            //this.addRepos(repIDs,repos);
134
            resultSet.addAll(repos);
135

  
132 136
            page+=1;
133 137
            uriComponents = UriComponentsBuilder
134 138
                    .fromHttpUrl(baseAddress + "/ds/search/country/")
135 139
                    .path("/{page}/{size}/")
136
                    .queryParam("country",country)
140
                    .queryParam("country",countryCode)
137 141
                    .build().expand(page,size).encode();
138 142
            rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
139 143
        }
140

  
141 144
        return resultSet;
142 145
    }
143 146

  
147
    private String getCountryCode(String country) {
148

  
149
        Country[] countries = getCountries();
150
        for(Country c : countries)
151
            if(c.getName().equals(country))
152
                return c.getCode();
153
        return country;
154
    }
155

  
144 156
    private void addRepos(Set<String> resultSet, Collection<String> repos) {
145 157
        for(String s : repos)
146 158
            if(!resultSet.contains(s))
147 159
                resultSet.add(s);
148 160
    }
149 161

  
150
    private Collection<String> getRepositoriesByMode(String mode, List<Repository> rs) {
162
    private Collection<Repository> getRepositoriesByMode(String mode, List<Repository> rs) {
151 163

  
152
        List<String> reps = new ArrayList<>();
164
        List<Repository> reps = new ArrayList<>();
153 165

  
154 166
        for(Repository r : rs)
155 167
            if(r.getCollectedFrom().equals(mode))
156
                reps.add(r.getOfficialName());
168
                reps.add(r);
157 169

  
158 170
        return reps;
159 171
    }
......
170 182
                .queryParam("contactemail",userEmail)
171 183
                .build().expand(page,size).encode();
172 184
        
173
        LOGGER.debug("URI -> " + uriComponents.toUri());
174 185
        String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
175
        LOGGER.debug("Repositories are : " + rs);
176 186
        return Converter.jsonToRepositoryList(new JSONArray(rs));
177 187
    }
178 188

  
......
375 385
        return vocabularyMap.get(vocName);
376 386
    }
377 387

  
388

  
389
    @Override
390
    public Map<String, String> getCompatibilityClasses(@PathVariable("mode") String mode)  {
391

  
392
        LOGGER.debug("Getting compatibility classes for mode: " + mode);
393
        Map<String, String> retMap = new HashMap<String, String>();
394

  
395
        Map<String, String> compatibilityClasses = this.getVocabulary("dnet:compatibilityLevel").getAsMap();
396
        boolean foundData = false;
397
        for (Map.Entry<String, String> entry : compatibilityClasses.entrySet()) {
398
            if (mode.equalsIgnoreCase(Constants.REPOSITORY_MODE_ALL))
399
                return compatibilityClasses;
400
            else if (mode.equalsIgnoreCase(Constants.REPOSITORY_MODE_RE3DATA)) {
401
                if (entry.getKey().matches("^openaire[1-9].0_data$")) {
402
                    retMap.put(entry.getKey(), entry.getValue());
403
                    foundData = true;
404
                }
405
            } else {
406
                if (entry.getKey().matches("^openaire[1-9].0$") || entry.getKey().equals("driver"))
407
                    retMap.put(entry.getKey(), entry.getValue());
408
            }
409
        }
410

  
411
        //TODO TO BE REMOVED WHEN VOCABULARIES ARE UPDATED
412
        if (mode.equalsIgnoreCase(Constants.REPOSITORY_MODE_RE3DATA) && !foundData)
413
            retMap.put("openaire2.0_data", "OpenAIRE Data (funded, referenced datasets)");
414

  
415
        return retMap;
416
    }
417

  
418
    @Override
419
    public Map<String, String> getDatasourceClasses(@PathVariable("mode") String mode)  {
420

  
421
        LOGGER.debug("Getting datasource classes for mode: " + mode);
422

  
423
        Map<String, String> retMap = new HashMap<String, String>();
424

  
425
        for (Map.Entry<String, String> entry : this.getVocabulary("dnet:datasource_typologies").getAsMap().entrySet()) {
426
            if (mode.equalsIgnoreCase("aggregator")) {
427
                if (entry.getKey().contains("aggregator"))
428
                    retMap.put(entry.getKey(), entry.getValue());
429
            } else if (mode.equalsIgnoreCase("journal")) {
430
                if (entry.getKey().contains("journal"))
431
                    retMap.put(entry.getKey(), entry.getValue());
432
            } else if (mode.equalsIgnoreCase("opendoar")) {
433
                if (entry.getKey().contains("pubsrepository"))
434
                    retMap.put(entry.getKey(), entry.getValue());
435
            } else if (mode.equalsIgnoreCase("re3data")) {
436
                if (entry.getKey().contains("datarepository"))
437
                    retMap.put(entry.getKey(), entry.getValue());
438
            }
439
        }
440
        return retMap;
441

  
442
    }
443

  
378 444
}

Also available in: Unified diff