2020-07-03 12:09:22 +02:00
|
|
|
package eu.dnetlib.organizations.controller;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.security.core.Authentication;
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
2021-01-27 12:17:38 +01:00
|
|
|
import eu.dnetlib.common.controller.AbstractDnetController;
|
2020-10-08 15:10:11 +02:00
|
|
|
import eu.dnetlib.organizations.model.utils.VocabularyTerm;
|
2020-07-03 12:09:22 +02:00
|
|
|
import eu.dnetlib.organizations.utils.DatabaseUtils;
|
|
|
|
import eu.dnetlib.organizations.utils.DatabaseUtils.VocabularyTable;
|
|
|
|
import eu.dnetlib.organizations.utils.RelationType;
|
|
|
|
import eu.dnetlib.organizations.utils.SimilarityType;
|
|
|
|
|
|
|
|
@RestController
|
2021-01-27 12:17:38 +01:00
|
|
|
public class VocabulariesController extends AbstractDnetController {
|
2020-07-03 12:09:22 +02:00
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private DatabaseUtils databaseUtils;
|
|
|
|
|
|
|
|
@GetMapping("/api/vocabularies")
|
2020-10-08 15:10:11 +02:00
|
|
|
public Map<String, List<VocabularyTerm>> ListVocabularies(final Authentication authentication) {
|
|
|
|
final Map<String, List<VocabularyTerm>> vocs = new HashMap<>();
|
2020-07-03 12:09:22 +02:00
|
|
|
vocs.put("orgTypes", databaseUtils.listValuesOfVocabularyTable(VocabularyTable.org_types));
|
|
|
|
vocs.put("idTypes", databaseUtils.listValuesOfVocabularyTable(VocabularyTable.id_types));
|
|
|
|
vocs.put("languages", databaseUtils.listValuesOfVocabularyTable(VocabularyTable.languages));
|
|
|
|
|
2020-10-08 15:10:11 +02:00
|
|
|
vocs.put("relTypes", Arrays.stream(RelationType.values())
|
2021-10-21 11:54:57 +02:00
|
|
|
.map(t -> new VocabularyTerm(t.name(), t.name()))
|
2020-10-08 15:10:11 +02:00
|
|
|
.collect(Collectors.toList()));
|
2021-10-21 11:54:57 +02:00
|
|
|
|
2020-10-08 15:10:11 +02:00
|
|
|
vocs.put("similaritiesType", Arrays.stream(SimilarityType.values())
|
|
|
|
.map(t -> new VocabularyTerm(t.toString(), t.toString()))
|
|
|
|
.collect(Collectors.toList()));
|
2020-07-03 12:09:22 +02:00
|
|
|
|
|
|
|
if (UserInfo.isSimpleUser(authentication) || UserInfo.isNationalAdmin(authentication)) {
|
2020-11-23 12:02:33 +01:00
|
|
|
vocs.put("countries", databaseUtils.listCountriesForUser(UserInfo.getEmail(authentication)));
|
2020-07-03 12:09:22 +02:00
|
|
|
} else if (UserInfo.isSuperAdmin(authentication)) {
|
|
|
|
vocs.put("countries", databaseUtils.listValuesOfVocabularyTable(VocabularyTable.countries));
|
|
|
|
} else {
|
2020-10-08 15:10:11 +02:00
|
|
|
vocs.put("countries", new ArrayList<VocabularyTerm>());
|
2020-07-03 12:09:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return vocs;
|
|
|
|
}
|
|
|
|
|
2020-10-08 15:10:11 +02:00
|
|
|
@GetMapping({
|
|
|
|
"/api/voc/allCountries", "/registration_api/voc/allCountries"
|
|
|
|
})
|
|
|
|
public List<VocabularyTerm> allCountries() {
|
2020-07-03 12:09:22 +02:00
|
|
|
return databaseUtils.listValuesOfVocabularyTable(VocabularyTable.countries);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|