Revision 52781
Added by Panagiotis Kanakakis almost 6 years ago
PiWikApiImpl.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import com.fasterxml.jackson.databind.ObjectMapper; |
4 | 4 |
import eu.dnetlib.domain.data.PiwikInfo; |
5 |
import eu.dnetlib.domain.data.Repository; |
|
6 | 5 |
import eu.dnetlib.repo.manager.shared.RepositoryServiceException; |
7 | 6 |
import org.apache.commons.codec.digest.DigestUtils; |
7 |
import org.apache.log4j.Logger; |
|
8 | 8 |
import org.springframework.beans.factory.annotation.Autowired; |
9 | 9 |
import org.springframework.beans.factory.annotation.Qualifier; |
10 | 10 |
import org.springframework.beans.factory.annotation.Value; |
11 | 11 |
import org.springframework.dao.EmptyResultDataAccessException; |
12 |
import org.springframework.http.HttpStatus; |
|
13 |
import org.springframework.http.ResponseEntity; |
|
12 | 14 |
import org.springframework.jdbc.core.JdbcTemplate; |
13 | 15 |
import org.springframework.jdbc.core.RowMapper; |
16 |
import org.springframework.security.access.prepost.PostAuthorize; |
|
14 | 17 |
import org.springframework.security.access.prepost.PreAuthorize; |
15 | 18 |
import org.springframework.stereotype.Component; |
16 | 19 |
import org.springframework.web.bind.annotation.PathVariable; |
... | ... | |
29 | 32 |
@Component |
30 | 33 |
public class PiWikApiImpl implements PiWikApi{ |
31 | 34 |
|
35 |
@Qualifier("repomanager.dataSource") |
|
32 | 36 |
@Autowired |
33 |
@Qualifier("repomanager.dataSource") |
|
34 | 37 |
private DataSource dataSource; |
35 | 38 |
|
36 | 39 |
|
... | ... | |
42 | 45 |
@Qualifier("emailUtils") |
43 | 46 |
EmailUtils emailUtils; |
44 | 47 |
|
45 |
private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger
|
|
48 |
private static final Logger LOGGER = Logger
|
|
46 | 49 |
.getLogger(PiWikApiImpl.class); |
47 | 50 |
|
48 | 51 |
private final static String GET_PIWIK_SITE = "select repositoryid, siteid, authenticationtoken, creationdate, requestorname, requestoremail, validated, validationdate, comment, repositoryname, country from piwik_site where repositoryid = ?;"; |
... | ... | |
92 | 95 |
|
93 | 96 |
@Override |
94 | 97 |
@PreAuthorize("hasRole('ROLE_ADMIN')") |
95 |
public void approvePiwikSite(@PathVariable("repositoryId") String repositoryId) {
|
|
98 |
public ResponseEntity<Object> approvePiwikSite(@PathVariable("repositoryId") String repositoryId) {
|
|
96 | 99 |
new JdbcTemplate(dataSource).update(APPROVE_PIWIK_SITE, new Object[] {repositoryId}, new int[] {Types.VARCHAR}); |
100 |
return new ResponseEntity<>("OK",HttpStatus.OK); |
|
97 | 101 |
} |
98 | 102 |
|
99 | 103 |
@Override |
... | ... | |
105 | 109 |
|
106 | 110 |
@Override |
107 | 111 |
@PreAuthorize("hasRole('ROLE_ADMIN')") |
108 |
public void markPiwikSiteAsValidated(@PathVariable("repositoryId") String repositoryId) throws RepositoryServiceException {
|
|
112 |
public ResponseEntity<Object> markPiwikSiteAsValidated(@PathVariable("repositoryId") String repositoryId) throws RepositoryServiceException {
|
|
109 | 113 |
try { |
110 | 114 |
approvePiwikSite(repositoryId); |
111 | 115 |
|
... | ... | |
121 | 125 |
LOGGER.error("Error while sending email to administrator or user about the enabling of metrics", e); |
122 | 126 |
emailUtils.reportException(e); |
123 | 127 |
} |
128 |
return new ResponseEntity<>("OK",HttpStatus.OK); |
|
124 | 129 |
} |
125 | 130 |
|
126 | 131 |
@Override |
127 |
@PreAuthorize("hasRole('ROLE_USER')")
|
|
128 |
public void enableMetricsForRepository(@RequestParam("officialName") String officialName,
|
|
129 |
@RequestParam("repoWebsite") String repoWebsite, |
|
130 |
@RequestBody PiwikInfo piwikInfo) throws RepositoryServiceException { |
|
132 |
@PreAuthorize("hasRole('ROLE_ADMIN') or (hasRole('ROLE_USER') and #piwikInfo.requestorEmail == authentication.userInfo.email)")
|
|
133 |
public PiwikInfo enableMetricsForRepository(@RequestParam("officialName") String officialName,
|
|
134 |
@RequestParam("repoWebsite") String repoWebsite,
|
|
135 |
@RequestBody PiwikInfo piwikInfo) throws RepositoryServiceException {
|
|
131 | 136 |
|
132 | 137 |
try { |
133 | 138 |
|
... | ... | |
155 | 160 |
LOGGER.error("Error while sending email to administrator or user about the request to enable metrics", e); |
156 | 161 |
emailUtils.reportException(e); |
157 | 162 |
} |
163 |
return piwikInfo; |
|
158 | 164 |
} |
159 | 165 |
|
160 | 166 |
|
Also available in: Unified diff
1. Dockerize service
2. Add authorization checks
3. Handle exceptions ( controller advice, exception package)
4. Login-logout operations bug fixes