Project

General

Profile

« Previous | Next » 

Revision 51525

1. Add roles for aai
2. Changes on converter file for new interface object
3. Move emailUtils to avoid bug on bean definitions
4. Add openaire provider authorities mapper class
5. Bug fixes on controllers

View differences:

PiWikApiImpl.java
1 1
package eu.dnetlib.repo.manager.service.controllers;
2 2

  
3
import com.fasterxml.jackson.databind.ObjectMapper;
3 4
import eu.dnetlib.domain.data.PiwikInfo;
4
import eu.dnetlib.utils.md5.MD5;
5
import eu.dnetlib.repo.manager.shared.RepositoryServiceException;
5 6
import org.apache.commons.codec.digest.DigestUtils;
6 7
import org.springframework.beans.factory.annotation.Autowired;
7 8
import org.springframework.beans.factory.annotation.Qualifier;
9
import org.springframework.beans.factory.annotation.Value;
8 10
import org.springframework.dao.EmptyResultDataAccessException;
9 11
import org.springframework.jdbc.core.JdbcTemplate;
10 12
import org.springframework.jdbc.core.RowMapper;
......
12 14
import org.springframework.web.bind.annotation.PathVariable;
13 15
import org.springframework.web.bind.annotation.RequestBody;
14 16

  
15
import javax.annotation.PostConstruct;
16 17
import javax.sql.DataSource;
17
import java.security.NoSuchAlgorithmException;
18
import java.sql.ResultSet;
19
import java.sql.SQLException;
18
import java.io.IOException;
19
import java.io.UnsupportedEncodingException;
20
import java.net.URL;
21
import java.net.URLEncoder;
20 22
import java.sql.Types;
21 23
import java.util.List;
24
import java.util.Map;
22 25

  
23 26
@Component
24 27
public class PiWikApiImpl implements PiWikApi{
......
27 30
    @Qualifier("repomanager.dataSource")
28 31
    private DataSource dataSource;
29 32

  
33

  
34
    @Value("${services.repomanager.analyticsURL}")
35
    private String analyticsURL;
36

  
37

  
38
    @Autowired
39
    @Qualifier("emailUtils")
40
    EmailUtils emailUtils;
41

  
30 42
    private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger
31 43
            .getLogger(PiWikApiImpl.class);
32 44

  
......
39 51
    private final static String APPROVE_PIWIK_SITE = "update piwik_site set validated=true, validationdate=now() where repositoryid = ?;";
40 52

  
41 53

  
54

  
42 55
    private RowMapper<PiwikInfo> piwikRowMapper = (rs, i) -> new PiwikInfo(rs.getString("repositoryid"), getOpenaireId(rs.getString("repositoryid")), rs.getString("repositoryname"), rs.getString("country"),
43 56
            rs.getString("siteid"), rs.getString("authenticationtoken"), rs.getTimestamp("creationdate"), rs.getString("requestorname"), rs.getString("requestoremail"),
44 57
            rs.getBoolean("validated"), rs.getTimestamp("validationdate"), rs.getString("comment"));
......
85 98
        return null;
86 99
    }
87 100

  
101
    @Override
102
    public void markPiwikSiteAsValidated(@PathVariable("repositoryId") String repositoryId) throws RepositoryServiceException {
103
        try {
104
            approvePiwikSite(repositoryId);
88 105

  
106
            PiwikInfo piwikInfo = getPiwikSiteForRepo(repositoryId);
107
            emailUtils.sendAdministratorMetricsEnabled(piwikInfo);
108
            emailUtils.sendUserMetricsEnabled(piwikInfo);
109

  
110
        } catch (EmptyResultDataAccessException e) {
111
            LOGGER.error("Error while approving piwik site: ", e);
112
            emailUtils.reportException(e);
113
            throw new RepositoryServiceException("General error", RepositoryServiceException.ErrorCode.GENERAL_ERROR);
114
        } catch (Exception e) {
115
            LOGGER.error("Error while sending email to administrator or user about the enabling of metrics", e);
116
            emailUtils.reportException(e);
117
        }
118
    }
119

  
120
    @Override
121
    public void enableMetricsForRepository(@RequestBody PiwikInfo piwikInfo) throws RepositoryServiceException {
122

  
123
        try {
124
            String URL = analyticsURL + "siteName=" + URLEncoder.encode(piwikInfo.getRepositoryName(), "UTF-8")
125
                    + "&url=" + piwikInfo.getSiteId();
126
            Map<String, Object> map = new ObjectMapper().readValue(new URL(URL), Map.class);
127

  
128
           /* String siteId = null;
129
            if(map.get("value")!=null) {
130
                siteId = map.get("value").toString();
131
            }
132

  
133
            String authenticationToken = "32846584f571be9b57488bf4088f30ea";
134

  
135
            PiwikInfo piwikInfo = new PiwikInfo();
136
            piwikInfo.setRepositoryId(repository.getId());
137
            piwikInfo.setRepositoryName(repository.getOfficialName());
138
            piwikInfo.setCountry(repository.getCountryName());
139
            piwikInfo.setSiteId(siteId);
140
            piwikInfo.setAuthenticationToken(authenticationToken);
141
            piwikInfo.setRequestorEmail(userProfile.getEmail());
142
            piwikInfo.setRequestorName(userProfile.getFirstname() + " " + userProfile.getLastname());
143
            piwikInfo.setValidated(false);
144
*/
145
            savePiwikInfo(piwikInfo);
146

  
147
            emailUtils.sendAdministratorRequestToEnableMetrics(piwikInfo);
148
            emailUtils.sendUserRequestToEnableMetrics(piwikInfo);
149

  
150
        } catch (UnsupportedEncodingException uee) {
151
            LOGGER.error("Error while creating piwikScript URL", uee);
152
            emailUtils.reportException(uee);
153
            throw new RepositoryServiceException("login.generalError", RepositoryServiceException.ErrorCode.GENERAL_ERROR);
154
        } catch (IOException ioe) {
155
            LOGGER.error("Error while creating piwik site", ioe);
156
            emailUtils.reportException(ioe);
157
            throw new RepositoryServiceException("login.generalError", RepositoryServiceException.ErrorCode.GENERAL_ERROR);
158
        } catch (Exception e) {
159
            LOGGER.error("Error while sending email to administrator or user about the request to enable metrics", e);
160
            emailUtils.reportException(e);
161
        }
162
    }
163

  
164

  
89 165
}

Also available in: Unified diff