Revision 57596
Added by Michele Artini over 4 years ago
DatabaseUtils.java | ||
---|---|---|
9 | 9 |
import org.springframework.cache.annotation.Cacheable; |
10 | 10 |
import org.springframework.jdbc.core.JdbcTemplate; |
11 | 11 |
import org.springframework.stereotype.Component; |
12 |
import org.springframework.web.bind.annotation.RequestBody; |
|
12 | 13 |
|
13 | 14 |
import eu.dnetlib.organizations.model.Acronym; |
14 | 15 |
import eu.dnetlib.organizations.model.Organization; |
... | ... | |
16 | 17 |
import eu.dnetlib.organizations.model.OtherName; |
17 | 18 |
import eu.dnetlib.organizations.model.Relationship; |
18 | 19 |
import eu.dnetlib.organizations.model.Url; |
20 |
import eu.dnetlib.organizations.model.User; |
|
21 |
import eu.dnetlib.organizations.model.UserCountry; |
|
19 | 22 |
import eu.dnetlib.organizations.model.view.OrganizationView; |
23 |
import eu.dnetlib.organizations.model.view.UserView; |
|
20 | 24 |
import eu.dnetlib.organizations.repository.AcronymRepository; |
21 | 25 |
import eu.dnetlib.organizations.repository.OrganizationRepository; |
22 | 26 |
import eu.dnetlib.organizations.repository.OtherIdentifierRepository; |
23 | 27 |
import eu.dnetlib.organizations.repository.OtherNameRepository; |
24 | 28 |
import eu.dnetlib.organizations.repository.RelationshipRepository; |
25 | 29 |
import eu.dnetlib.organizations.repository.UrlRepository; |
30 |
import eu.dnetlib.organizations.repository.UserCountryRepository; |
|
31 |
import eu.dnetlib.organizations.repository.UserRepository; |
|
26 | 32 |
|
27 | 33 |
@Component |
28 | 34 |
public class DatabaseUtils { |
... | ... | |
39 | 45 |
private UrlRepository urlRepository; |
40 | 46 |
@Autowired |
41 | 47 |
private RelationshipRepository relationshipRepository; |
48 |
@Autowired |
|
49 |
private UserRepository userRepository; |
|
50 |
@Autowired |
|
51 |
private UserCountryRepository userCountryRepository; |
|
42 | 52 |
|
43 | 53 |
@Autowired |
44 | 54 |
private JdbcTemplate jdbcTemplate; |
... | ... | |
119 | 129 |
return jdbcTemplate.queryForList("select country from user_countries where email = ?", String.class, name); |
120 | 130 |
} |
121 | 131 |
|
132 |
@Transactional |
|
133 |
public void saveUser(@RequestBody final UserView userView) { |
|
134 |
|
|
135 |
final User user = userRepository.findById(userView.getEmail()).orElseThrow(() -> new RuntimeException("User not found")); |
|
136 |
user.setRole(userView.getRole()); |
|
137 |
user.setValid(userView.isValid()); |
|
138 |
userRepository.save(user); |
|
139 |
|
|
140 |
userCountryRepository.deleteByEmail(userView.getEmail()); |
|
141 |
for (final String country : userView.getCountries()) { |
|
142 |
userCountryRepository.save(new UserCountry(userView.getEmail(), country)); |
|
143 |
} |
|
144 |
} |
|
145 |
|
|
146 |
@Transactional |
|
147 |
public void deleteUser(final String email) { |
|
148 |
userCountryRepository.deleteByEmail(email); |
|
149 |
userRepository.deleteById(email); |
|
150 |
} |
|
151 |
|
|
122 | 152 |
} |
Also available in: Unified diff
User Registration form