1 |
56405
|
michele.ar
|
package eu.dnetlib.organizations.controller;
|
2 |
|
|
|
3 |
57661
|
michele.ar
|
import java.util.ArrayList;
|
4 |
57130
|
michele.ar
|
import java.util.Arrays;
|
5 |
56405
|
michele.ar
|
import java.util.HashMap;
|
6 |
|
|
import java.util.List;
|
7 |
|
|
import java.util.Map;
|
8 |
57130
|
michele.ar
|
import java.util.stream.Collectors;
|
9 |
56405
|
michele.ar
|
|
10 |
57099
|
michele.ar
|
import org.springframework.beans.factory.annotation.Autowired;
|
11 |
57320
|
michele.ar
|
import org.springframework.security.core.Authentication;
|
12 |
57650
|
michele.ar
|
import org.springframework.web.bind.annotation.GetMapping;
|
13 |
56405
|
michele.ar
|
import org.springframework.web.bind.annotation.RestController;
|
14 |
|
|
|
15 |
57099
|
michele.ar
|
import eu.dnetlib.organizations.utils.DatabaseUtils;
|
16 |
|
|
import eu.dnetlib.organizations.utils.DatabaseUtils.VocabularyTable;
|
17 |
57130
|
michele.ar
|
import eu.dnetlib.organizations.utils.RelationType;
|
18 |
|
|
import eu.dnetlib.organizations.utils.SimilarityType;
|
19 |
57099
|
michele.ar
|
|
20 |
56405
|
michele.ar
|
@RestController
|
21 |
|
|
public class VocabulariesController {
|
22 |
|
|
|
23 |
57099
|
michele.ar
|
@Autowired
|
24 |
|
|
private DatabaseUtils databaseUtils;
|
25 |
|
|
|
26 |
57661
|
michele.ar
|
@GetMapping("/api/vocabularies")
|
27 |
57320
|
michele.ar
|
public Map<String, List<String>> ListVocabularies(final Authentication authentication) {
|
28 |
56405
|
michele.ar
|
final Map<String, List<String>> vocs = new HashMap<>();
|
29 |
57099
|
michele.ar
|
vocs.put("orgTypes", databaseUtils.listValuesOfVocabularyTable(VocabularyTable.org_types));
|
30 |
|
|
vocs.put("idTypes", databaseUtils.listValuesOfVocabularyTable(VocabularyTable.id_types));
|
31 |
|
|
vocs.put("languages", databaseUtils.listValuesOfVocabularyTable(VocabularyTable.languages));
|
32 |
57320
|
michele.ar
|
|
33 |
57130
|
michele.ar
|
vocs.put("relTypes", Arrays.stream(RelationType.values()).map(Object::toString).collect(Collectors.toList()));
|
34 |
|
|
vocs.put("similaritiesType", Arrays.stream(SimilarityType.values()).map(Object::toString).collect(Collectors.toList()));
|
35 |
57320
|
michele.ar
|
|
36 |
57661
|
michele.ar
|
if (UserInfo.isSimpleUser(authentication) || UserInfo.isNationalAdmin(authentication)) {
|
37 |
57650
|
michele.ar
|
vocs.put("countries", databaseUtils.listCountriesForUser(authentication.getName()));
|
38 |
57661
|
michele.ar
|
} else if (UserInfo.isSuperAdmin(authentication)) {
|
39 |
|
|
vocs.put("countries", databaseUtils.listValuesOfVocabularyTable(VocabularyTable.countries));
|
40 |
57650
|
michele.ar
|
} else {
|
41 |
57661
|
michele.ar
|
vocs.put("countries", new ArrayList<String>());
|
42 |
57320
|
michele.ar
|
}
|
43 |
|
|
|
44 |
56405
|
michele.ar
|
return vocs;
|
45 |
|
|
}
|
46 |
|
|
|
47 |
57661
|
michele.ar
|
@GetMapping({ "/api/voc/allCountries", "/registration_api/voc/allCountries" })
|
48 |
|
|
public List<String> allCountries() {
|
49 |
|
|
return databaseUtils.listValuesOfVocabularyTable(VocabularyTable.countries);
|
50 |
|
|
}
|
51 |
|
|
|
52 |
56405
|
michele.ar
|
}
|