Revision 51656
Added by Panagiotis Kanakakis about 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; |
|
5 | 6 |
import eu.dnetlib.repo.manager.shared.RepositoryServiceException; |
6 | 7 |
import org.apache.commons.codec.digest.DigestUtils; |
7 | 8 |
import org.springframework.beans.factory.annotation.Autowired; |
... | ... | |
10 | 11 |
import org.springframework.dao.EmptyResultDataAccessException; |
11 | 12 |
import org.springframework.jdbc.core.JdbcTemplate; |
12 | 13 |
import org.springframework.jdbc.core.RowMapper; |
14 |
import org.springframework.security.access.prepost.PreAuthorize; |
|
13 | 15 |
import org.springframework.stereotype.Component; |
14 | 16 |
import org.springframework.web.bind.annotation.PathVariable; |
15 | 17 |
import org.springframework.web.bind.annotation.RequestBody; |
18 |
import org.springframework.web.bind.annotation.RequestParam; |
|
16 | 19 |
|
17 | 20 |
import javax.sql.DataSource; |
18 | 21 |
import java.io.IOException; |
... | ... | |
67 | 70 |
} |
68 | 71 |
|
69 | 72 |
@Override |
73 |
@PreAuthorize("hasRole('ROLE_ADMIN')") |
|
70 | 74 |
public PiwikInfo savePiwikInfo(@RequestBody PiwikInfo piwikInfo) { |
71 | 75 |
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); |
72 | 76 |
jdbcTemplate.update(INSERT_PIWIK_INFO, new Object[]{piwikInfo.getRepositoryId(), piwikInfo.getSiteId(), piwikInfo.getRequestorName(), |
... | ... | |
87 | 91 |
} |
88 | 92 |
|
89 | 93 |
@Override |
94 |
@PreAuthorize("hasRole('ROLE_ADMIN')") |
|
90 | 95 |
public void approvePiwikSite(@PathVariable("repositoryId") String repositoryId) { |
91 | 96 |
new JdbcTemplate(dataSource).update(APPROVE_PIWIK_SITE, new Object[] {repositoryId}, new int[] {Types.VARCHAR}); |
92 | 97 |
} |
... | ... | |
99 | 104 |
} |
100 | 105 |
|
101 | 106 |
@Override |
107 |
@PreAuthorize("hasRole('ROLE_ADMIN')") |
|
102 | 108 |
public void markPiwikSiteAsValidated(@PathVariable("repositoryId") String repositoryId) throws RepositoryServiceException { |
103 | 109 |
try { |
104 | 110 |
approvePiwikSite(repositoryId); |
... | ... | |
118 | 124 |
} |
119 | 125 |
|
120 | 126 |
@Override |
121 |
public void enableMetricsForRepository(@RequestBody PiwikInfo piwikInfo) throws RepositoryServiceException { |
|
127 |
@PreAuthorize("hasRole('ROLE_USER')") |
|
128 |
public void enableMetricsForRepository(@RequestParam("officialName") String officialName, |
|
129 |
@RequestParam("repoWebsite") String repoWebsite, |
|
130 |
@RequestBody PiwikInfo piwikInfo) throws RepositoryServiceException { |
|
122 | 131 |
|
123 | 132 |
try { |
133 |
|
|
134 |
String URL = analyticsURL + "siteName=" + URLEncoder.encode(officialName, "UTF-8") + "&url=" |
|
135 |
+ URLEncoder.encode(repoWebsite, "UTF-8"); |
|
136 |
Map map = new ObjectMapper().readValue(new URL(URL), Map.class); |
|
137 |
String siteId = null; |
|
138 |
if(map.get("value")!=null) { |
|
139 |
siteId = map.get("value").toString(); |
|
140 |
} |
|
141 |
piwikInfo.setSiteId(siteId); |
|
142 |
|
|
124 | 143 |
savePiwikInfo(piwikInfo); |
125 | 144 |
emailUtils.sendAdministratorRequestToEnableMetrics(piwikInfo); |
126 | 145 |
emailUtils.sendUserRequestToEnableMetrics(piwikInfo); |
Also available in: Unified diff
Add PreAuthorize annotation on user methods.