Revision 57661
Added by Michele Artini over 4 years ago
OrganizationController.java | ||
---|---|---|
8 | 8 |
import java.util.Map; |
9 | 9 |
import java.util.Set; |
10 | 10 |
import java.util.TreeMap; |
11 |
import java.util.stream.Collectors; |
|
12 | 11 |
|
13 | 12 |
import org.apache.commons.lang3.StringUtils; |
14 | 13 |
import org.springframework.beans.factory.annotation.Autowired; |
... | ... | |
34 | 33 |
import eu.dnetlib.organizations.repository.readonly.OrganizationViewRepository; |
35 | 34 |
import eu.dnetlib.organizations.repository.readonly.WarningViewRepository; |
36 | 35 |
import eu.dnetlib.organizations.utils.DatabaseUtils; |
37 |
import eu.dnetlib.organizations.utils.OpenOrgsConstants; |
|
38 | 36 |
import eu.dnetlib.organizations.utils.RelationType; |
39 | 37 |
|
40 | 38 |
@RestController |
... | ... | |
62 | 60 |
throw new RuntimeException("Missing field: country"); |
63 | 61 |
} else if (StringUtils.isBlank(org.getType())) { |
64 | 62 |
throw new RuntimeException("Missing field: type"); |
65 |
} else if (UserInfo.isSuperUser(authentication) || organizationRepository.verifyAuthorizationForCountry(org.getCountry(), authentication.getName())) {
|
|
63 |
} else if (UserInfo.isSuperAdmin(authentication) || organizationRepository.verifyAuthorizationForCountry(org.getCountry(), authentication.getName())) {
|
|
66 | 64 |
final String orgId = databaseUtils.insertOrUpdateOrganization(org, authentication.getName(), StringUtils.isNotBlank(org.getId())); |
67 | 65 |
return Arrays.asList(orgId); |
68 | 66 |
} else { |
... | ... | |
74 | 72 |
public OrganizationView findById(@RequestParam final String id, final Authentication authentication) { |
75 | 73 |
final OrganizationView org = organizationViewRepository.findById(id).get(); |
76 | 74 |
|
77 |
if (UserInfo.isSuperUser(authentication) || organizationRepository.verifyAuthorizationForCountry(org.getCountry(), authentication.getName())) {
|
|
75 |
if (UserInfo.isSuperAdmin(authentication) || organizationRepository.verifyAuthorizationForCountry(org.getCountry(), authentication.getName())) {
|
|
78 | 76 |
return org; |
79 | 77 |
} else { |
80 | 78 |
throw new RuntimeException("User not authorized"); |
... | ... | |
83 | 81 |
|
84 | 82 |
@RequestMapping(value = "/relations", method = RequestMethod.GET) |
85 | 83 |
public List<RelationByOrg> findRelationsById(@RequestParam final String id, final Authentication authentication) { |
86 |
if (UserInfo.isSuperUser(authentication) || organizationRepository.verifyAuthorizationForId(id, authentication.getName())) {
|
|
84 |
if (UserInfo.isSuperAdmin(authentication) || organizationRepository.verifyAuthorizationForId(id, authentication.getName())) {
|
|
87 | 85 |
return organizationViewRepository.findRelations(id); |
88 | 86 |
} else { |
89 | 87 |
throw new RuntimeException("User not authorized"); |
... | ... | |
97 | 95 |
final Authentication authentication) { |
98 | 96 |
if (from.equals(to)) { |
99 | 97 |
throw new IllegalArgumentException("Invalid relation !!!"); |
100 |
} else if (UserInfo.isSuperUser(authentication)
|
|
98 |
} else if (UserInfo.isSuperAdmin(authentication)
|
|
101 | 99 |
|| organizationRepository.verifyAuthorizationForId(to, authentication.getName()) |
102 | 100 |
|| organizationRepository.verifyAuthorizationForId(from, authentication.getName())) { |
103 | 101 |
|
... | ... | |
117 | 115 |
final Authentication authentication) { |
118 | 116 |
if (from.equals(to)) { |
119 | 117 |
throw new IllegalArgumentException("Invalid relation !!!"); |
120 |
} else if (UserInfo.isSuperUser(authentication)
|
|
118 |
} else if (UserInfo.isSuperAdmin(authentication)
|
|
121 | 119 |
|| organizationRepository.verifyAuthorizationForId(to, authentication.getName()) |
122 | 120 |
|| organizationRepository.verifyAuthorizationForId(from, authentication.getName())) { |
123 | 121 |
|
... | ... | |
132 | 130 |
|
133 | 131 |
@RequestMapping(value = "/similarities", method = RequestMethod.GET) |
134 | 132 |
public List<OpenaireSimRel> findSimilaritiesById(@RequestParam final String id, final Authentication authentication) { |
135 |
if (UserInfo.isSuperUser(authentication) || organizationRepository.verifyAuthorizationForId(id, authentication.getName())) { |
|
136 |
return openaireSimRelRepository.findByLocalId(id).stream().filter(s -> !s.getOaOriginalId().startsWith(OpenOrgsConstants.OPENORGS_PREFIX)).collect(Collectors.toList()); |
|
133 |
if (UserInfo.isSuperAdmin(authentication) || organizationRepository.verifyAuthorizationForId(id, authentication.getName())) { |
|
134 |
// return openaireSimRelRepository.findByLocalId(id).stream().filter(s -> |
|
135 |
// !s.getOaOriginalId().startsWith(OpenOrgsConstants.OPENORGS_PREFIX)).collect(Collectors.toList()); |
|
136 |
return openaireSimRelRepository.findByLocalId(id); |
|
137 | 137 |
} else { |
138 | 138 |
throw new RuntimeException("User not authorized"); |
139 | 139 |
} |
... | ... | |
146 | 146 |
|
147 | 147 |
final Map<String, String> roots = new HashMap<>(); |
148 | 148 |
|
149 |
if (UserInfo.isSuperUser(authentication)) {
|
|
149 |
if (UserInfo.isSuperAdmin(authentication)) {
|
|
150 | 150 |
for (final WarningView w : warningViewRepository.findAll()) { |
151 | 151 |
final String root = findWarningRoot(w, roots); |
152 | 152 |
if (!res.containsKey(root)) { |
... | ... | |
178 | 178 |
@RequestMapping(value = "/similarities", method = RequestMethod.POST) |
179 | 179 |
public List<OpenaireSimRel> saveSimilarities(@RequestBody final List<OpenaireSimRel> simrels, final Authentication authentication) { |
180 | 180 |
|
181 |
final boolean b = UserInfo.isSuperUser(authentication) |
|
182 |
|| simrels.stream().map(OpenaireSimRel::getLocalId).distinct().allMatch(id -> organizationRepository.verifyAuthorizationForId(id, authentication.getName())); |
|
181 |
final boolean b = UserInfo.isSuperAdmin(authentication) |
|
182 |
|| simrels.stream() |
|
183 |
.map(OpenaireSimRel::getLocalId) |
|
184 |
.distinct() |
|
185 |
.allMatch(id -> organizationRepository.verifyAuthorizationForId(id, authentication.getName())); |
|
183 | 186 |
|
184 | 187 |
if (b) { |
185 | 188 |
return openaireSimRelRepository.saveAll(simrels); |
... | ... | |
193 | 196 |
@PathVariable final int size, |
194 | 197 |
@RequestParam final String q, |
195 | 198 |
final Authentication authentication) { |
196 |
return UserInfo.isSuperUser(authentication)
|
|
199 |
return UserInfo.isSuperAdmin(authentication)
|
|
197 | 200 |
? organizationSimpleViewRepository.findByNameContainingIgnoreCase(q, PageRequest.of(page, size)) |
198 | 201 |
: organizationSimpleViewRepository.findByNameForUser(q, authentication.getName(), PageRequest.of(page, size)); |
199 | 202 |
} |
... | ... | |
203 | 206 |
@PathVariable final int page, |
204 | 207 |
@PathVariable final int size, |
205 | 208 |
final Authentication authentication) { |
206 |
if (UserInfo.isSuperUser(authentication) || organizationRepository.verifyAuthorizationForCountry(code, authentication.getName())) {
|
|
209 |
if (UserInfo.isSuperAdmin(authentication) || organizationRepository.verifyAuthorizationForCountry(code, authentication.getName())) {
|
|
207 | 210 |
return organizationSimpleViewRepository.findByCountry(code, PageRequest.of(page, size)); |
208 | 211 |
} else { |
209 | 212 |
throw new RuntimeException("User not authorized"); |
... | ... | |
215 | 218 |
@PathVariable final int page, |
216 | 219 |
@PathVariable final int size, |
217 | 220 |
final Authentication authentication) { |
218 |
return UserInfo.isSuperUser(authentication)
|
|
221 |
return UserInfo.isSuperAdmin(authentication)
|
|
219 | 222 |
? organizationSimpleViewRepository.findByType(type, PageRequest.of(page, size)) |
220 | 223 |
: organizationSimpleViewRepository.findByTypeForUser(type, authentication.getName(), PageRequest.of(page, size)); |
221 | 224 |
} |
222 | 225 |
|
223 | 226 |
@RequestMapping(value = "/browse/countries", method = RequestMethod.GET) |
224 | 227 |
public List<BrowseEntry> browseCountries(final Authentication authentication) { |
225 |
return UserInfo.isSuperUser(authentication)
|
|
228 |
return UserInfo.isSuperAdmin(authentication)
|
|
226 | 229 |
? organizationSimpleViewRepository.browseCountries() |
227 | 230 |
: organizationSimpleViewRepository.browseCountriesForUser(authentication.getName()); |
228 | 231 |
} |
229 | 232 |
|
230 | 233 |
@RequestMapping(value = "/browse/types", method = RequestMethod.GET) |
231 | 234 |
public List<BrowseEntry> browseOrganizationTypes(final Authentication authentication) { |
232 |
return UserInfo.isSuperUser(authentication)
|
|
235 |
return UserInfo.isSuperAdmin(authentication)
|
|
233 | 236 |
? organizationSimpleViewRepository.browseTypes() |
234 | 237 |
: organizationSimpleViewRepository.browseTypesForUser(authentication.getName()); |
235 | 238 |
} |
Also available in: Unified diff
national admin management