Project

General

Profile

« Previous | Next » 

Revision 61527

tagging release 2.0.0

View differences:

modules/uoa-repository-manager-service/tags/release-2.0.0/src/main/java/eu/dnetlib/repo/manager/service/security/RoleMappingService.java
1
package eu.dnetlib.repo.manager.service.security;
2

  
3
import org.springframework.security.core.GrantedAuthority;
4
import org.springframework.security.core.authority.SimpleGrantedAuthority;
5

  
6
import java.util.Collection;
7

  
8
public interface RoleMappingService {
9

  
10
    /**
11
     * @param fullName
12
     * @param prefix
13
     * @return
14
     */
15
    String getRepoNameWithoutType(String fullName, String prefix);
16

  
17
    /**
18
     * @param roleId Role Id
19
     * @return Converts {@param roleId} to a repo Id.
20
     */
21
    String getRepoIdByRoleId(String roleId);
22

  
23
    /**
24
     *
25
     * @param roleIds Collection of roles
26
     * @return Converts {@param roleIds} to a repo Ids.
27
     */
28
    Collection<String> getRepoIdsByRoleIds(Collection<String> roleIds);
29

  
30
    /**
31
     * @param repoId Repository Id
32
     * @return Converts {@param repoId} to a role Id.
33
     */
34
    String getRoleIdByRepoId(String repoId);
35

  
36
    /**
37
     * @param repoIds Collection of Repository Ids
38
     * @return Converts {@param repoIds} to role Ids.
39
     */
40
    Collection<String> getRoleIdsByRepoIds(Collection<String> repoIds);
41

  
42
    /**
43
     * @param authorityId Authority Id
44
     * @return Converts {@param authorityId} to repo Id.
45
     */
46
    String convertAuthorityIdToRepoId(String authorityId);
47

  
48
    /**
49
     * @param authority Granted authority
50
     * @return Converts {@param authority} to repo Id.
51
     */
52
    String convertAuthorityToRepoId(GrantedAuthority authority);
53

  
54
    /**
55
     * @param repoId Repository Id
56
     * @return
57
     */
58
    String convertRepoIdToAuthorityId(String repoId);
59

  
60
    /**
61
     * @param repoId Repository Id
62
     * @return Converts {@param repoId} to {@link String} role id url encoded ($ -> %24)
63
     * // TODO: remove role encoding and perform url decoding when mapping authorities. (Must be performed in all OpenAIRE projects because of Redis)
64
     */
65
    String convertRepoIdToEncodedAuthorityId(String repoId);
66

  
67
    /**
68
     * @param repoId Repository Id
69
     * @return Converts {@param repoId} to {@link SimpleGrantedAuthority} with the role url encoded ($ -> %24)
70
     * // TODO: remove role encoding and perform url decoding when mapping authorities. (Must be performed in all OpenAIRE projects because of Redis)
71
     */
72
    SimpleGrantedAuthority convertRepoIdToAuthority(String repoId);
73

  
74
}
modules/uoa-repository-manager-service/tags/release-2.0.0/src/main/java/eu/dnetlib/repo/manager/service/security/AuthoritiesUpdater.java
1
package eu.dnetlib.repo.manager.service.security;
2

  
3
import org.apache.log4j.Logger;
4
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
5
import org.springframework.beans.factory.annotation.Autowired;
6
import org.springframework.security.core.Authentication;
7
import org.springframework.security.core.GrantedAuthority;
8
import org.springframework.security.core.context.SecurityContext;
9
import org.springframework.security.core.context.SecurityContextHolder;
10
import org.springframework.security.oauth2.common.exceptions.UnauthorizedClientException;
11
import org.springframework.security.web.context.HttpSessionSecurityContextRepository;
12
import org.springframework.session.ExpiringSession;
13
import org.springframework.session.FindByIndexNameSessionRepository;
14
import org.springframework.stereotype.Service;
15

  
16
import java.util.Collection;
17
import java.util.HashSet;
18
import java.util.Map;
19

  
20

  
21
@Service
22
public class AuthoritiesUpdater extends HttpSessionSecurityContextRepository {
23

  
24
    private static final Logger logger = Logger.getLogger(AuthoritiesUpdater.class);
25

  
26
    @Autowired
27
    FindByIndexNameSessionRepository sessions;
28

  
29
    public void update(String email, Collection<? extends GrantedAuthority> authorities) {
30
        if (sessions != null) {
31
            Map<String, ExpiringSession> map = sessions.
32
                    findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, email);
33
            if (map != null) {
34
                logger.debug(map.values().toArray().length);
35
                for (ExpiringSession session : map.values()) {
36
                    logger.debug(session.getId());
37
                    if (!session.isExpired()) {
38
                        SecurityContext securityContext = session.getAttribute(SPRING_SECURITY_CONTEXT_KEY);
39
                        Authentication authentication = securityContext.getAuthentication();
40
                        if (authentication instanceof OIDCAuthenticationToken) {
41
                            OIDCAuthenticationToken authOIDC = (OIDCAuthenticationToken) authentication;
42
                            logger.debug(authorities);
43
                            securityContext.setAuthentication(new OIDCAuthenticationToken(authOIDC.getSub(), authOIDC.getIssuer(),
44
                                    authOIDC.getUserInfo(), authorities, authOIDC.getIdToken(),
45
                                    authOIDC.getAccessTokenValue(), authOIDC.getRefreshTokenValue()));
46
                            logger.debug("Update authorities");
47
                            session.setAttribute(SPRING_SECURITY_CONTEXT_KEY, securityContext);
48
                            sessions.save(session);
49
                        }
50
                    }
51
                }
52
            }
53
        }
54
    }
55

  
56
    public void update(String email, Update update) {
57
        Collection<? extends GrantedAuthority> authorities = update.authorities(SecurityContextHolder.getContext().getAuthentication().getAuthorities());
58
        this.update(email, authorities);
59
    }
60

  
61
    public void addRole(String email, GrantedAuthority role) {
62
        this.update(email, old -> {
63
            HashSet<GrantedAuthority> authorities = new HashSet<>(old);
64
            authorities.add(role);
65
            return authorities;
66
        });
67
    }
68

  
69
    public void addRole(GrantedAuthority role) {
70
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
71
        if (auth instanceof OIDCAuthenticationToken) {
72
            OIDCAuthenticationToken oidcAuth = (OIDCAuthenticationToken) auth;
73
            this.addRole(oidcAuth.getUserInfo().getEmail(), role);
74
        } else {
75
            throw new UnauthorizedClientException("User auth is not instance of OIDCAuthenticationToken");
76
        }
77
    }
78

  
79
    public void removeRole(String email, GrantedAuthority role) {
80
        this.update(email, old -> {
81
            HashSet<GrantedAuthority> authorities = new HashSet<>(old);
82
            authorities.remove(role);
83
            return authorities;
84
        });
85
    }
86

  
87
    public void removeRole(GrantedAuthority role) {
88
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
89
        if (auth instanceof OIDCAuthenticationToken) {
90
            OIDCAuthenticationToken oidcAuth = (OIDCAuthenticationToken) auth;
91
            this.removeRole(oidcAuth.getUserInfo().getEmail(), role);
92
        }
93
    }
94

  
95
    public interface Update {
96
        Collection<? extends GrantedAuthority> authorities(Collection<? extends GrantedAuthority> old);
97
    }
98
}
modules/uoa-repository-manager-service/tags/release-2.0.0/src/main/java/eu/dnetlib/repo/manager/service/StatsService.java
1
package eu.dnetlib.repo.manager.service;
2

  
3
import java.util.Map;
4

  
5

  
6
public interface StatsService {
7

  
8
    Map getStatistics() ;
9
}
modules/uoa-repository-manager-service/tags/release-2.0.0/src/main/java/eu/dnetlib/repo/manager/service/DashboardService.java
1
package eu.dnetlib.repo.manager.service;
2

  
3
import eu.dnetlib.repo.manager.domain.RepositorySummaryInfo;
4
import org.json.JSONException;
5
import org.springframework.web.bind.annotation.PathVariable;
6

  
7
import java.util.List;
8

  
9
public interface DashboardService {
10

  
11
    List<RepositorySummaryInfo> getRepositoriesSummaryInfo(@PathVariable("userEmail") String userEmail,
12
                                                           @PathVariable("page") String page,
13
                                                           @PathVariable("size") String size) throws JSONException;
14
}
modules/uoa-repository-manager-service/tags/release-2.0.0/src/main/java/eu/dnetlib/repo/manager/service/EmailUtilsImpl.java
1
package eu.dnetlib.repo.manager.service;
2

  
3
import eu.dnetlib.domain.data.PiwikInfo;
4
import eu.dnetlib.domain.data.Repository;
5
import eu.dnetlib.domain.data.RepositoryInterface;
6
import eu.dnetlib.domain.functionality.validator.JobForValidation;
7
import eu.dnetlib.repo.manager.config.CascadingPropertyLoader;
8
import eu.dnetlib.repo.manager.domain.ValidationServiceException;
9
import eu.dnetlib.utils.MailLibrary;
10
import org.apache.log4j.Logger;
11
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
12
import org.springframework.beans.factory.annotation.Autowired;
13
import org.springframework.beans.factory.annotation.Value;
14
import org.springframework.security.core.Authentication;
15
import org.springframework.security.core.context.SecurityContextHolder;
16
import org.springframework.stereotype.Component;
17

  
18
import javax.annotation.PostConstruct;
19
import java.io.PrintWriter;
20
import java.io.StringWriter;
21
import java.io.Writer;
22
import java.util.ArrayList;
23
import java.util.List;
24
import java.util.stream.Collectors;
25

  
26

  
27
@Component("emailUtils")
28
public class EmailUtilsImpl implements EmailUtils {
29

  
30
    private static Logger LOGGER = Logger.getLogger(EmailUtilsImpl.class);
31

  
32
    private List<String> specialRecipients = new ArrayList<String>();
33
    private boolean override = false, logonly = false;
34
    private String overrideEmail = null, from = null;
35

  
36
    private final MailLibrary mailLibrary;
37
    private final CascadingPropertyLoader pLoader;
38
    private final RepositoryService repositoryService;
39

  
40
    @Value("${services.repo-manager.baseUrl}")
41
    private String baseUrl;
42

  
43
    @Value("${services.repo-manager.adminEmail}")
44
    private String adminEmail;
45

  
46
    @Value("${services.repomanager.usagestats.adminEmail}")
47
    private String usageStatsAdminEmail;
48

  
49
    @Value("${services.provide.adminEmail}")
50
    private String provideAdminEmail;
51

  
52
    @Value("${validator.results.url}")
53
    private String valBaseUrl;
54

  
55
    @Autowired
56
    EmailUtilsImpl(MailLibrary mailLibrary, CascadingPropertyLoader pLoader,
57
                   RepositoryService repositoryService) {
58
        this.mailLibrary = mailLibrary;
59
        this.pLoader = pLoader;
60
        this.repositoryService = repositoryService;
61
    }
62

  
63

  
64
    @PostConstruct
65
    public void init(){
66
        System.out.println("url -> " + this.baseUrl);
67
    }
68

  
69

  
70
    @Override
71
    public void reportException(Exception exception) {
72
        Writer writer = new StringWriter();
73
        PrintWriter printWriter = new PrintWriter(writer);
74
        exception.printStackTrace(printWriter);
75

  
76
        List<String> recipients = new ArrayList<String>();
77

  
78
        try {
79
            recipients.add(this.adminEmail);
80
            String message = "An exception has occurred:\n"+writer.toString();
81
            String subject = "Automatic Bug Report";
82
            this.sendMail(recipients, subject, message, false, null);
83
        } catch (Exception e) {
84
            LOGGER.error("Error sending error report", e);
85
        }
86
    }
87

  
88
    @Override
89
    public void sendAdministratorRequestToEnableMetrics(PiwikInfo piwikInfo) throws Exception {
90

  
91
        try {
92
            String subject = "[OpenAIRE-Usage Statistics] New request to enable usage statistics";
93

  
94
            String message = "Dear administrator,\n" +
95
                    "\n" +
96
                    "we have received a request to enable the OpenAIRE usage statistics for the following repository \n" +
97
                    "\n" +
98
                    "Repository - " + piwikInfo.getRepositoryName() + ", " + piwikInfo.getCountry() + " (" + piwikInfo.getRepositoryId() + ")\n" +
99
                    "Requestor - " + piwikInfo.getRequestorName() + ", " + piwikInfo.getRequestorEmail() + "\n" +
100
                    "Matomo ID - " + piwikInfo.getSiteId() + "\n" +
101
                    "Authentication token - " + piwikInfo.getAuthenticationToken() + "\n" +
102
                    "\n" +
103
                    "For more information about this request, go here: \n" +
104
                    this.baseUrl + "/admin/metrics\n" +
105
                    "\n" +
106
                    "Best,\n" +
107
                    "The OpenAIRE team";
108

  
109
            this.sendMail(this.usageStatsAdminEmail, subject, message, false, null);
110

  
111
        } catch (Exception e) {
112
            LOGGER.error("Error while sending request to enable metrics email to administrator: " + this.usageStatsAdminEmail, e);
113
            throw e;
114
        }
115
    }
116

  
117
    @Override
118
    public void sendUserRequestToEnableMetrics(PiwikInfo piwikInfo) throws Exception {
119

  
120
        try {
121
            String subject = "[OpenAIRE-Usage Statistics] Your request to enable usage statistics";
122

  
123
            String message = "Dear " + piwikInfo.getRequestorName() + ",\n" +
124
                    "\n" +
125
                    "we have received your request to enable the OpenAIRE usage statistics for your repository\n" +
126
                    "\n" +
127
                    "Repository - " + piwikInfo.getRepositoryName() + ", " + piwikInfo.getCountry() + " (" + piwikInfo.getRepositoryId() + ")\n" +
128
                    "Matomo ID - " + piwikInfo.getSiteId() + "\n" +
129
                    "Authentication token - " + piwikInfo.getAuthenticationToken() + "\n" +
130
                    "\n" +
131
                    "In order to enable the usage statistics, you must install the OpenAIRE's tracking code in your repository software. " +
132
                    "OpenAIRE's usage statistics service tracking code is maintained on Github as a patch for various versions of DSpace " +
133
                    "(https://github.com/openaire/OpenAIRE-Piwik-DSpace) and as an Eprints plugin for version 3 " +
134
                    "(https://github.com/openaire/EPrints-OAPiwik). In case the platform is different from DSpace or EPrints please contact " +
135
                    "the OpenAIRE team in repositoryusagestats@openaire.eu in order to find a solution.\n" +
136
                    "\n" +
137
                    "For more information about your request and configuration details, go here: \n" +
138
                    this.baseUrl + "/getImpact/instructions/" + piwikInfo.getRepositoryId() + "\n" +
139
                    "\n" +
140
                    "Once you have finished configuring your repository or if you have any questions, please notify the OpenAIRE team by sending \n" +
141
                    "an email to repositoryusagestats@openaire.eu\n" +
142
                    "\n" +
143
                    "Best,\n" +
144
                    "The OpenAIRE team";
145

  
146
            this.sendMail(piwikInfo.getRequestorEmail(), subject, message, false, null);
147

  
148
        } catch (Exception e) {
149
            LOGGER.error("Error while sending request to enable metrics email to user: " + piwikInfo.getRequestorEmail(), e);
150
            throw e;
151
        }
152
    }
153

  
154
    @Override
155
    public void sendAdministratorMetricsEnabled(PiwikInfo piwikInfo) throws Exception {
156

  
157
        try {
158
            String subject = "[OpenAIRE-Usage Statistics] Usage statistics have been enabled";
159

  
160
            String message = "Dear administrator,\n" +
161
                    "\n" +
162
                    "The installation and configuration of OpenAIRE's tracking code for the following repository " +
163
                    "has been completed and validated and the usage statistics have been enabled in OpenAIRE.\n" +
164
                    "\n" +
165
                    "Repository - " + piwikInfo.getRepositoryName() + ", " + piwikInfo.getCountry() + " (" + piwikInfo.getRepositoryId() + ")\n" +
166
                    "Requestor - " + piwikInfo.getRequestorName() + ", " + piwikInfo.getRequestorEmail() + "\n" +
167
                    "Piwik ID - " + piwikInfo.getSiteId() + "\n" +
168
                    "Authentication token - " + piwikInfo.getAuthenticationToken() + "\n" +
169
                    "\n" +
170
                    "Best,\n" +
171
                    "The OpenAIRE team";
172

  
173
            this.sendMail(this.usageStatsAdminEmail, subject, message, false, null);
174

  
175
        } catch (Exception e) {
176
            LOGGER.error("Error while sending metrics enabled notification email to administator: " + this.usageStatsAdminEmail, e);
177
            throw e;
178
        }
179
    }
180

  
181
    @Override
182
    public void sendUserMetricsEnabled(PiwikInfo piwikInfo) throws Exception {
183

  
184
        try {
185
            String subject = "[OpenAIRE-Usage Statistics] Usage statistics have been enabled";
186

  
187
            String message = "Dear " + piwikInfo.getRequestorName() + ",\n" +
188
                    "\n" +
189
                    "The installation and configuration of OpenAIRE's tracking code for your repository \"" + piwikInfo.getRepositoryName() +
190
                    "\" has been completed and validated and the usage statistics have been enabled in OpenAIRE.\n" +
191
                    "\n" +
192
                    "You can preview the statistics in your repository's dashboard: \n" +
193
                    this.baseUrl + "/getImpact/" + piwikInfo.getRepositoryId() + "\n" +
194
                    "\n" +
195
                    " For more information and questions, you can contact the openaire support team by sending an email to " +
196
                    "repositoryusagestats@openaire.eu\n" +
197
                    "\n" +
198
                    "Best,\n" +
199
                    "The OpenAIRE team";
200

  
201
            this.sendMail(piwikInfo.getRequestorEmail(), subject, message, false, null);
202

  
203
        } catch (Exception e) {
204
            LOGGER.error("Error while sending metrics enabled notification email to user: " + piwikInfo.getRequestorEmail(), e);
205
            throw e;
206
        }
207
    }
208

  
209
    @Override
210
    public void sendAdminRegistrationEmail(Repository repository, Authentication authentication) throws Exception {
211
        try {
212
            String subject = "OpenAIRE content provider registration for " +
213
                    repository.getDatasourceType() + "[" + repository.getOfficialName() + "]";
214

  
215
            String message = "Dear administrator" + ",\n" +
216
                    "\n" +
217
                    "We received a request to register the " + repository.getDatasourceType() + "[" + repository.getOfficialName() + "]" +
218
                    " to the OpenAIRE compliant list of content providers. " +
219
                    "\n\n" +
220
                    "User Contact: " + authentication.getName() + " (" + ((OIDCAuthenticationToken) authentication).getUserInfo().getEmail() + ")" +
221
                    "\n\n" +
222
                    "Please do not reply to this message\n" +
223
                    "This message has been generated automatically.\n\n" +
224
                    "Regards,\n" +
225
                    "the OpenAIRE technical team\n";
226

  
227
            this.sendMail(this.provideAdminEmail, subject, message, false, null);
228

  
229
        } catch (Exception e) {
230
            LOGGER.error("Error while sending registration notification email to the administrator", e);
231
            throw e;
232
        }
233
    }
234

  
235
    @Override
236
    public void sendUserRegistrationEmail(Repository repository, Authentication authentication) throws Exception {
237
        try {
238
            String subject = "OpenAIRE content provider registration for " +
239
                    repository.getDatasourceType() + "[" + repository.getOfficialName() + "]";
240

  
241
//            String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
242
            String message = "Dear "+SecurityContextHolder.getContext().getAuthentication().getName()+",\n" +
243
                    "\n" +
244
                    "We received a request to register the " + repository.getDatasourceType() + "[" + repository.getOfficialName() + "]" +
245
                    " to the OpenAIRE compliant list of content providers. " +
246
                    "\n\n" +
247
                    "Please do not reply to this message\n" +
248
                    "This message has been generated automatically.\n\n" +
249
                    "If you have any questions, write to 'helpdesk@openaire.eu'. \n\n" +
250
                    "Regards,\n" +
251
                    "the OpenAIRE technical team\n";
252

  
253
            this.sendMail(repository.getRegisteredBy(), subject, message, false, null);
254

  
255
        } catch (Exception e) {
256
            LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredBy(), e);
257
            throw e;
258
        }
259
    }
260

  
261
    @Override
262
    public void sendAdminRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception {
263
        try {
264
            String subject = "OpenAIRE new interface registration request started for " +
265
                    repository.getDatasourceType() + "[" + repository.getOfficialName() + "]";
266

  
267
            String message = "Dear administrator" + ",\n" +
268
                    "\n" +
269
                    "We received a request to add the following interface: \n\n" +
270
                    "Base URL: " + repositoryInterface.getBaseUrl() + "\n" +
271
                    "Set: " + repositoryInterface.getAccessSet() + "\n" +
272
                    "Guidelines: " + repositoryInterface.getDesiredCompatibilityLevel() + "\n\n" +
273
                    "to " + repository.getDatasourceType() + "[" + repository.getOfficialName() + "].\n";
274

  
275
            if (comment != null)
276
                message += "\nThe users comment was '" + comment + "'\n";
277

  
278
            message += "A validation process for this interface against the OpenAIRE guidelines compatibility " +
279
                    "has been started. You will be informed in another message once the process is finished." +
280
                    "\n\n" +
281
                    "User Contact: " + authentication.getName() + " (" + ((OIDCAuthenticationToken) authentication).getUserInfo().getEmail() + ")" +
282
                    "\n\n" +
283
                    "Please do not reply to this message\n" +
284
                    "This message has been generated automatically.\n\n" +
285
                    "Regards,\n" +
286
                    "the OpenAIRE technical team\n";
287

  
288
            this.sendMail(this.provideAdminEmail, subject, message, false, null);
289

  
290
        } catch (Exception e) {
291
            LOGGER.error("Error while sending registration of interface notification email to the administrator", e);
292
            throw e;
293
        }
294
    }
295

  
296
    @Override
297
    public void sendUserRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception {
298
        try {
299
            String subject = "OpenAIRE new interface registration request started for " +
300
                    repository.getDatasourceType() + "[" + repository.getOfficialName() + "]";
301

  
302
            String message = "Dear "+SecurityContextHolder.getContext().getAuthentication().getName()+",\n" +
303
                    "\n" +
304
                    "We received a request to add the following interface: \n\n" +
305
                    "Base URL: " + repositoryInterface.getBaseUrl() + "\n" +
306
                    "Set: " + repositoryInterface.getAccessSet() + "\n" +
307
                    "Guidelines: " + repositoryInterface.getDesiredCompatibilityLevel() + "\n\n" +
308
                    "to " + repository.getDatasourceType() + "[" + repository.getOfficialName() + "].\n";
309

  
310
            if (comment != null) {
311
                message += "\n Your comment was '" + comment + "'\n";
312
            }
313

  
314
            message += "A validation process for this interface against the OpenAIRE guidelines compatibility " +
315
                    "has been started. You will be informed in another message once the process is finished." +
316
                    "\n\n" +
317
                    "Please do not reply to this message\n" +
318
                    "This message has been generated automatically.\n\n" +
319
                    "Regards,\n" +
320
                    "the OpenAIRE technical team\n";
321

  
322
            this.sendMail(repository.getRegisteredBy(), subject, message, false, null);
323

  
324
        } catch (Exception e) {
325
            LOGGER.error("Error while sending registration of interface notification email to user: " + repository.getRegisteredBy(), e);
326
            throw e;
327
        }
328
    }
329

  
330
    @Override
331
    public void sendUserRegistrationResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception {
332
        try {
333
            String subject = "OpenAIRE new interface registration request - results (success) for " +
334
                    repository.getDatasourceType() + "[" + repository.getOfficialName() + "]";
335

  
336
//            String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
337
            String message = "Dear user,\n" +
338
                    "\n" +
339
                    "the compatibility test on " + "[" + repository.getOfficialName() + "]" +
340
                    " was successful and the datasource type \""+ repository.getDatasourceType()  + "\" will be prepared for aggregation in OpenAIRE."+
341
                    "\n\n" +
342
                    "Please note that it usually takes about 3-4 weeks until a data source is indexed and it’s metadata visible on openaire.eu.\n\n" +
343
                    "Registration identifier in OpenAIRE: "+ repository.getNamespacePrefix()+
344
                    "\nOfficial Name:" + repository.getOfficialName() +
345
                    "\n\nBase URL: "+ repositoryInterface.getBaseUrl() +
346
                    "\n\nValidation Set: " + repositoryInterface.getAccessSet() +
347
                    "\n\nGuidelines: "+ repositoryInterface.getDesiredCompatibilityLevel() +
348
                    "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId +
349
                    "\n\n\nPlease do not reply to this email\n"+
350
                    "This message has been generated manually\n\n"+
351
                    "If you have any questions, write to 'helpdesk@openaire.eu'. \n\n" +
352
                    "Regards,\n" +
353
                    "the OpenAIRE technical team\n";
354

  
355
            this.sendMail(repository.getRegisteredBy(), subject, message, false, null);
356

  
357
        } catch (Exception e) {
358
            LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredBy(), e);
359
            throw e;
360
        }
361
    }
362

  
363
    @Override
364
    public void sendAdminRegistrationResultsSuccessEmail(String issuerEmail, String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception {
365
        try {
366
            String subject = "OpenAIRE new interface registration request - results (success) for " +
367
                    repository.getDatasourceType() + "[" + repository.getOfficialName() + "]";
368

  
369
            String message = "Dear admin ,\n" +
370
                    "\n" +
371
                    "the compatibility test on " + "[" + repository.getOfficialName() + "]" +
372
                    " was successful and the datasource type \""+ repository.getDatasourceType()  + "\" will be prepared for aggregation in OpenAIRE."+
373
                    "\n\n" +
374
                    "Please note that it usually takes about 3-4 weeks until a data source is indexed and it’s metadata visible on openaire.eu.\n\n" +
375
                    "Registration identifier in OpenAIRE: "+ repository.getNamespacePrefix()+
376
                    "\nOfficial Name:" + repository.getOfficialName() +
377
                    "\n\nBase URL: "+ repositoryInterface.getBaseUrl() +
378
                    "\n\nValidation Set: " + repositoryInterface.getAccessSet() +
379
                    "\n\nGuidelines: "+ repositoryInterface.getDesiredCompatibilityLevel() +
380
                    "\n\nUser Contact:"+ issuerEmail +""+
381
                    "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId +
382
                    "\n\n\nPlease do not reply to this email\n"+
383
                    "This message has been generated manually\n\n"+
384
                    "If you have any questions, write to 'helpdesk@openaire.eu'. \n\n" +
385
                    "Regards,\n" +
386
                    "the OpenAIRE technical team\n";
387

  
388
            this.sendMail(this.provideAdminEmail, subject, message, false, null);
389

  
390
        } catch (Exception e) {
391
            LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredBy(), e);
392
            throw e;
393
        }
394
    }
395

  
396
    @Override
397
    public void sendUserRegistrationResultsFailureEmail(String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception {
398
        try {
399
            String subject = "OpenAIRE new interface registration request - results (failure) for " +
400
                    repository.getDatasourceType() + "[" + repository.getOfficialName() + "]";
401
            //            String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
402
            String message = "Dear user,\n" +
403
                    "\n" +
404
                    "the compatibility test on " + "[" + repository.getOfficialName() + "]" +
405
                    " was not successful and the registration process was interrupted."+
406
                    "\n\n" +
407
                    "We will check what caused the problem and get back to you within a couple of days.\n\n" +
408
                    "Registration identifier in OpenAIRE: "+ repository.getNamespacePrefix()+
409
                    "\nOfficial Name:" + repository.getOfficialName() +
410
                    "\n\nBase URL: "+ repositoryInterface.getBaseUrl() +
411
                    "\n\nValidation Set: " + repositoryInterface.getAccessSet() +
412
                    "\n\nGuidelines: "+ repositoryInterface.getDesiredCompatibilityLevel() +
413
                    "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId +
414
                    "\n\n\nPlease do not reply to this email\n"+
415
                    "This message has been generated manually\n\n"+
416
                    "If you have any questions, write to 'helpdesk@openaire.eu'. \n\n" +
417
                    "Regards,\n" +
418
                    "the OpenAIRE technical team\n";
419

  
420
            this.sendMail(repository.getRegisteredBy(), subject, message, false, null);
421

  
422
        } catch (Exception e) {
423
            LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredBy(), e);
424
            throw e;
425
        }
426
    }
427

  
428
    @Override
429
    public void sendAdminRegistrationResultsFailureEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception {
430
        try {
431
            String subject = "OpenAIRE new interface registration request - results (failure) for " +
432
                    repository.getDatasourceType() + "[" + repository.getOfficialName() + "]";
433

  
434
            String message = "Dear admin,\n" +
435
                    "\n" +
436
                    "the compatibility test on " + "[" + repository.getOfficialName() + "]" +
437
                    " was not successful and the registration process was interrupted."+
438
                    "\n\n" +
439
                    "We will check what caused the problem and get back to you within a couple of days.\n\n" +
440
                    "Registration identifier in OpenAIRE: "+ repository.getNamespacePrefix()+
441
                    "\nOfficial Name:" + repository.getOfficialName() +
442
                    "\n\nBase URL: "+ repositoryInterface.getBaseUrl() +
443
                    "\n\nValidation Set: " + repositoryInterface.getAccessSet() +
444
                    "\n\nGuidelines: "+ repositoryInterface.getDesiredCompatibilityLevel() +
445
                    "\n\nUser Contact:"+ issuerEmail +""+
446
                    "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId +
447
                    "\n\n\nPlease do not reply to this email\n"+
448
                    "This message has been generated manually\n\n"+
449
                    "If you have any questions, write to 'helpdesk@openaire.eu'. \n\n" +
450
                    "Regards,\n" +
451
                    "the OpenAIRE technical team\n";
452

  
453
            this.sendMail(this.provideAdminEmail, subject, message, false, null);
454

  
455
        } catch (Exception e) {
456
            LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredBy(), e);
457
            throw e;
458
        }
459
    }
460

  
461
    @Override
462
    public void sendUserUpdateResultsSuccessEmail(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception {
463
        try {
464
            String subject = "OpenAIRE interface update request - results (success) for " +
465
                    repository.getDatasourceType() + "[" + repository.getOfficialName() + "]";
466

  
467
            //            String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
468
            String message = "Dear user,\n" +
469
                    "\n" +
470
                    "the compatibility test on [" + repository.getOfficialName()+"] has been successful\n\n" +
471
                    "We will check your transmitted information and adjust the aggregation settings accordingly. Please note that it usually takes about 3-4 weeks until the changes are visible on openaire.eu."+"\n\n" +
472
                    "Registration identifier in OpenAIRE: "+ repository.getNamespacePrefix()+
473
                    "\nOfficial Name:" + repository.getOfficialName() +
474
                    "\n\nBase URL: "+ repositoryInterface.getBaseUrl() +
475
                    "\n\nValidation Set: " + repositoryInterface.getAccessSet() +
476
                    "\n\nGuidelines: "+ repositoryInterface.getDesiredCompatibilityLevel() +
477
                    "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId +
478
                    "\n\n\nPlease do not reply to this email\n"+
479
                    "This message has been generated manually\n\n"+
480
                    "If you have any questions, write to 'helpdesk@openaire.eu'. \n\n" +
481
                    "Regards,\n" +
482
                    "the OpenAIRE technical team\n";
483

  
484
            this.sendMail(issuer, subject, message, false, null);
485

  
486
        } catch (Exception e) {
487
            LOGGER.error("Error while sending registration notification email to the administrator", e);
488
            throw e;
489
        }
490
    }
491

  
492
    @Override
493
    public void sendAdminUpdateResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception {
494
            try {
495
                String subject = "OpenAIRE interface update request - results (success) for " +
496
                        repository.getDatasourceType() + "[" + repository.getOfficialName() + "]";
497

  
498
                String message = "Dear admin,\n" +
499
                        "\n" +
500
                        "the compatibility test on [" + repository.getOfficialName()+"] has been successful\n\n" +
501
                        "We will check your transmitted information and adjust the aggregation settings accordingly. Please note that it usually takes about 3-4 weeks until the changes are visible on openaire.eu."+"\n\n" +
502
                        "Registration identifier in OpenAIRE: "+ repository.getNamespacePrefix()+
503
                        "\nOfficial Name:" + repository.getOfficialName() +
504
                        "\n\nBase URL: "+ repositoryInterface.getBaseUrl() +
505
                        "\n\nValidation Set: " + repositoryInterface.getAccessSet() +
506
                        "\n\nGuidelines: "+ repositoryInterface.getDesiredCompatibilityLevel() +
507
                        "\n\nUser Contact:"+ issuerEmail +""+
508
                        "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId +
509
                        "\n\n\nPlease do not reply to this email\n"+
510
                        "This message has been generated manually\n\n"+
511
                        "If you have any questions, write to 'helpdesk@openaire.eu'. \n\n" +
512
                        "Regards,\n" +
513
                        "the OpenAIRE technical team\n";
514

  
515
                this.sendMail(this.provideAdminEmail, subject, message, false, null);
516

  
517
            } catch (Exception e) {
518
                LOGGER.error("Error while sending registration notification email to the administrator", e);
519
                throw e;
520
            }
521
    }
522

  
523
    @Override
524
    public void sendUserUpdateResultsFailureEmail(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception {
525
        try {
526
            String subject = "OpenAIRE interface update request - results (failure) for " +
527
                    repository.getDatasourceType() + "[" + repository.getOfficialName() + "]";
528

  
529
            //            String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
530
            String message = "Dear user,\n" +
531
                    "\n" +
532
                    "the compatibility test on " + "[" + repository.getOfficialName() + "]" +
533
                    " was not successful."+
534
                    "\n\n" +
535
                    "WWe will check your transmitted information to see what caused the problem and get back to you within a couple of days.\n\n" +
536
                    "Registration identifier in OpenAIRE: "+ repository.getNamespacePrefix()+
537
                    "\nOfficial Name:" + repository.getOfficialName() +
538
                    "\n\nBase URL: "+ repositoryInterface.getBaseUrl() +
539
                    "\n\nValidation Set: " + repositoryInterface.getAccessSet() +
540
                    "\n\nGuidelines: "+ repositoryInterface.getDesiredCompatibilityLevel() +
541
                    "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId +
542
                    "\n\n\nPlease do not reply to this email\n"+
543
                    "This message has been generated manually\n\n"+
544
                    "If you have any questions, write to 'helpdesk@openaire.eu'. \n\n" +
545
                    "Regards,\n" +
546
                    "the OpenAIRE technical team\n";
547

  
548
            this.sendMail(issuer, subject, message, false, null);
549

  
550
        } catch (Exception e) {
551
            LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredBy(), e);
552
            throw e;
553
        }
554
    }
555

  
556
    @Override
557
    public void sendAdminUpdateResultsFailureEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception {
558
        try {
559
            String subject = "OpenAIRE interface update request - results (failure) for " +
560
                    repository.getDatasourceType() + "[" + repository.getOfficialName() + "]";
561

  
562
            String message = "Dear admin,\n" +
563
                    "\n" +
564
                    "the compatibility test on " + "[" + repository.getOfficialName() + "]" +
565
                    " was not successful."+
566
                    "\n\n" +
567
                    "WWe will check your transmitted information to see what caused the problem and get back to you within a couple of days.\n\n" +
568
                    "Registration identifier in OpenAIRE: "+ repository.getNamespacePrefix()+
569
                    "\nOfficial Name:" + repository.getOfficialName() +
570
                    "\n\nBase URL: "+ repositoryInterface.getBaseUrl() +
571
                    "\n\nValidation Set: " + repositoryInterface.getAccessSet() +
572
                    "\n\nGuidelines: "+ repositoryInterface.getDesiredCompatibilityLevel() +
573
                    "\n\nUser Contact:"+ issuerEmail +""+
574
                    "\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId +
575
                    "\n\n\nPlease do not reply to this email\n"+
576
                    "This message has been generated manually\n\n"+
577
                    "If you have any questions, write to 'helpdesk@openaire.eu'. \n\n" +
578
                    "Regards,\n" +
579
                    "the OpenAIRE technical team\n";
580

  
581
            this.sendMail(this.provideAdminEmail, subject, message, false, null);
582

  
583
        } catch (Exception e) {
584
            LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredBy(), e);
585
            throw e;
586
        }
587
    }
588

  
589
    @Override
590
    public void sendUserValidationResults(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception {
591
        try {
592
            String subject = "OpenAIRE validator - Test results ";
593

  
594
            //            String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
595
            String message = "Dear user,\n" +
596
                    "\n" +
597
                    "the validation request you have submitted has finished. You can retrieve the results by following this url: "+ valBaseUrl+"" + jobId+" .\n\n" +
598
                    "Please do not reply to this message.\n" +
599
                    "This message has been generated automatically.\n" +
600
                    "If you have any questions, write to 'helpdesk@openaire.eu'. \n\n" +
601
                    "Regards,\n" +
602
                    "the OpenAIRE technical team\n";
603

  
604
            this.sendMail(issuer, subject, message, false, null);
605

  
606
        } catch (Exception e) {
607
            LOGGER.error("Error while sending validation submission notification email to user: " + issuer, e);
608
            throw e;
609
        }
610
    }
611

  
612
    @Override
613
    public void sendAdminValidationResults(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception {
614
        try {
615
            String subject = "OpenAIRE validator - Test results ";
616

  
617
            String message = "Dear admin,\n" +
618
                    "\n" +
619
                    "a validation request has finished. You can retrieve the results by following this url: "+ valBaseUrl+"" + jobId+" .\n\n" +
620
                    "\n\nUser Contact:"+ issuer +""+
621
                    "Please do not reply to this message.\n" +
622
                    "This message has been generated automatically.\n" +
623
                    "If you have any questions, write to 'helpdesk@openaire.eu'. \n\n" +
624
                    "Regards,\n" +
625
                    "the OpenAIRE technical team\n";
626

  
627
            this.sendMail(this.provideAdminEmail, subject, message, false, null);
628

  
629
        } catch (Exception e) {
630
            LOGGER.error("Error while sending validation submission notification email to user: " + issuer, e);
631
            throw e;
632
        }
633
    }
634

  
635
    @Override
636
    public void sendAdminGeneralFailure(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception {
637
        try {
638
            String subject = "OpenAIRE validator - job failure";
639

  
640
            String message = "Dear admin,\n" +
641
                    "\n" +
642
                    "the validation job that was automatically submitted for the update/registration of the interface "+repositoryInterface.getId()+" ("+repositoryInterface.getBaseUrl()+", "+repositoryInterface.getAccessSet()+") of the repository "+repository.getId()+" ("+repository.getOfficialName()+") failed to complete." +
643
                    "This message has been generated automatically.\n\n" +
644
                    "Regards,\n" +
645
                    "the OpenAIRE technical team\n";
646

  
647
            this.sendMail(this.provideAdminEmail, subject, message, false, null);
648

  
649
        } catch (Exception e) {
650
            LOGGER.error("Error while sending validation submission notification email to user: " + issuer, e);
651
            throw e;
652
        }
653
    }
654

  
655
    @Override
656
    public void sendAdminUpdateRepositoryInfoEmail(Repository repository, Authentication authentication) throws Exception {
657
        try {
658
            String subject = "OpenAIRE content provider update information for " +
659
                    repository.getDatasourceType() + "[" + repository.getOfficialName() + "]";
660

  
661
            String message = "Dear administrator" + ",\n" +
662
                    "\n" +
663
                    "We received a request to update the basic information for " + repository.getDatasourceType() + "[" + repository.getOfficialName() + "].\n\n" +
664
                    "Please do not reply to this message\n" +
665
                    "This message has been generated automatically.\n\n" +
666
                    "Regards,\n" +
667
                    "the OpenAIRE technical team\n";
668

  
669
            this.sendMail(this.provideAdminEmail, subject, message, false, null);
670

  
671
        } catch (Exception e) {
672
            LOGGER.error("Error while sending registration notification email to the administrator", e);
673
            throw e;
674
        }
675
    }
676

  
677
    @Override
678
    public void sendUserUpdateRepositoryInfoEmail(Repository repository, Authentication authentication) throws Exception {
679
        try {
680
            String subject = "OpenAIRE content provider update information for " +
681
                    repository.getDatasourceType() + "[" + repository.getOfficialName() + "]";
682

  
683
            //            String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
684
            String message = "Dear user,\n" +
685
                    "\n" +
686
                    "We received a request to update the basic information for " + repository.getDatasourceType() + "[" + repository.getOfficialName() + "].\n\n" +
687
                    "Please do not reply to this message\n" +
688
                    "This message has been generated automatically.\n\n" +
689
                    "If you have any questions, write to 'helpdesk@openaire.eu'. \n\n" +
690
                    "Regards,\n" +
691
                    "the OpenAIRE technical team\n";
692

  
693
            this.sendMail(repository.getRegisteredBy(), subject, message, false, null);
694

  
695
        } catch (Exception e) {
696
            LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredBy(), e);
697
            throw e;
698
        }
699
    }
700

  
701
    @Override
702
    public void sendAdminUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception {
703
        try {
704
            String subject = "OpenAIRE interface update request started for " +
705
                    repository.getDatasourceType() + "[" + repository.getOfficialName() + "]";
706

  
707
            String message = "Dear administrator" + ",\n" +
708
                    "\n" +
709
                    "We received a request to update the following interface: \n\n" +
710
                    "Base URL: " + repositoryInterface.getBaseUrl() + "\n" +
711
                    "Set: " + repositoryInterface.getAccessSet() + "\n" +
712
                    "Guidelines: " + repositoryInterface.getDesiredCompatibilityLevel() + "\n\n" +
713
                    "for " + repository.getDatasourceType() + "[" + repository.getOfficialName() + "].\n";
714

  
715
            if (comment != null)
716
                message += "\nThe users comment was '" + comment + "'\n";
717

  
718
            message += "A new iteration process of the validation against the OpenAIRE guidelines compatibility has been started.\n\n" +
719
                    "User Contact: " + authentication.getName() + " (" + ((OIDCAuthenticationToken) authentication).getUserInfo().getEmail() + ")" +
720
                    "\n\n" +
721
                    "Please do not reply to this message\n" +
722
                    "This message has been generated automatically.\n\n" +
723
                    "Regards,\n" +
724
                    "the OpenAIRE technical team\n";
725

  
726
            this.sendMail(this.provideAdminEmail, subject, message, false, null);
727

  
728
        } catch (Exception e) {
729
            LOGGER.error("Error while sending registration notification email to the administrator", e);
730
            throw e;
731
        }
732
    }
733

  
734
    @Override
735
    public void sendUserUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception {
736
        try {
737
            String subject = "OpenAIRE interface update request started for " +
738
                    repository.getDatasourceType() + "[" + repository.getOfficialName() + "]";
739

  
740
            //            String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
741
            String message = "Dear user,\n" +
742
                    "\n" +
743
                    "We received a request to update the following interface: \n\n" +
744
                    "Base URL: " + repositoryInterface.getBaseUrl() + "\n" +
745
                    "Set: " + repositoryInterface.getAccessSet() + "\n" +
746
                    "Guidelines: " + repositoryInterface.getDesiredCompatibilityLevel() + "\n\n" +
747
                    "for " + repository.getDatasourceType() + "[" + repository.getOfficialName() + "].\n";
748

  
749
            if (comment != null) {
750
                message += "\n Your comment was '" + comment + "'\n";
751
            }
752

  
753
            message += "A new iteration process of the validation against the OpenAIRE guidelines compatibility has been started.\n\n" +
754
                    "Please do not reply to this message\n" +
755
                    "This message has been generated automatically.\n\n" +
756
                    "If you have any questions, write to 'helpdesk@openaire.eu'. \n\n" +
757
                    "Regards,\n" +
758
                    "the OpenAIRE technical team\n";
759

  
760
            this.sendMail(repository.getRegisteredBy(), subject, message, false, null);
761

  
762
        } catch (Exception e) {
763
            LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredBy(), e);
764
            throw e;
765
        }
766
    }
767

  
768
    @Override
769
    public void sendSubmitJobForValidationEmail(Authentication authentication, JobForValidation jobForValidation) throws Exception {
770
        try {
771
            String subject = "OpenAIRE validator - Test submission ";
772

  
773
            //            String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
774
            String message = "Dear user,\n" +
775
                    "\n" +
776
                    "The validation request you have submitted has started.\n" +
777
                    "Please do not reply to this message.\n" +
778
                    "This message has been generated automatically.\n" +
779
                    "If you have any questions, write to 'helpdesk@openaire.eu'. \n\n" +
780
                    "Regards,\n" +
781
                    "the OpenAIRE technical team\n";
782

  
783
            this.sendMail(jobForValidation.getUserEmail(), subject, message, false, null);
784

  
785
        } catch (Exception e) {
786
            LOGGER.error("Error while sending validation submission notification email to user: " + jobForValidation.getUserEmail(), e);
787
            throw e;
788
        }
789
    }
790

  
791
    @Override
792
    public void sendUponJobCompletion(
793
            String repoId,
794
            String repoInterfaceId,
795
            int scoreUsage,
796
            int scoreContent,
797
            boolean isSuccess,
798
            boolean isUpdate,
799
            String issuerEmail,
800
            String jobId) throws Exception {
801
        List<RepositoryInterface> repositoryInterfaces = repositoryService.getRepositoryInterface(repoId);
802
        if(repositoryInterfaces.size()==0)
803
            throw new ValidationServiceException("Repository interface with id \""+repoInterfaceId+"\" not found",ValidationServiceException.ErrorCode.GENERAL_ERROR);
804

  
805
        RepositoryInterface repositoryInterface = repositoryInterfaces.stream().filter( repoInterface -> repoInterface.getId().equals(repoInterfaceId)).collect(Collectors.toList()).get(0);
806
        Repository repository = repositoryService.getRepositoryById(repoId);
807

  
808
        if(!isUpdate){
809
            if(isSuccess){
810
                if(scoreContent>=50 && scoreUsage >= 50){
811
                    this.sendUserRegistrationResultsSuccessEmail(issuerEmail,jobId,repositoryInterface,repository, SecurityContextHolder.getContext().getAuthentication());
812
                    this.sendAdminRegistrationResultsSuccessEmail(issuerEmail,jobId,repositoryInterface,repository,SecurityContextHolder.getContext().getAuthentication());
813
                }else{
814
                    this.sendUserRegistrationResultsFailureEmail(jobId,repositoryInterface,repository, SecurityContextHolder.getContext().getAuthentication());
815
                    this.sendAdminRegistrationResultsFailureEmail(issuerEmail,jobId,repositoryInterface,repository,SecurityContextHolder.getContext().getAuthentication());
816
                }
817
            }else{
818
                this.sendAdminGeneralFailure(issuerEmail,jobId,repositoryInterface,repository,SecurityContextHolder.getContext().getAuthentication());
819
            }
820
        }else{
821
            if(isSuccess){
822
                if(scoreContent>=50 && scoreUsage >= 50){
823
                    this.sendUserUpdateResultsSuccessEmail(issuerEmail,jobId,repositoryInterface,repository, SecurityContextHolder.getContext().getAuthentication());
824
                    this.sendAdminUpdateResultsSuccessEmail(issuerEmail,jobId,repositoryInterface,repository, SecurityContextHolder.getContext().getAuthentication());
825
                }else{
826
                    this.sendUserUpdateResultsFailureEmail(issuerEmail,jobId,repositoryInterface,repository, SecurityContextHolder.getContext().getAuthentication());
827
                    this.sendAdminUpdateResultsFailureEmail(issuerEmail,jobId,repositoryInterface,repository, SecurityContextHolder.getContext().getAuthentication());
828
                }
829
            }else{
830
                this.sendAdminGeneralFailure(issuerEmail,jobId,repositoryInterface,repository,SecurityContextHolder.getContext().getAuthentication());
831
            }
832
        }
833

  
834
    }
835

  
836

  
837
    private void sendMail(String email, String subject, String message, boolean sendToSpecial, List<String> repoAdminMails) throws Exception {
838
        ArrayList<String> to = new ArrayList<String>();
839
        to.add(email);
840
        this.sendMail(to,subject,message,sendToSpecial,repoAdminMails);
841
    }
842

  
843
    public void sendMail(List<String> recipients, String subject, String message, boolean sendToSpecial, List<String> repoAdminMails) throws Exception {
844

  
845
        try {
846
            if (sendToSpecial) {
847
                recipients.addAll(this.specialRecipients);
848
            }
849

  
850
            if (repoAdminMails != null)
851
                recipients.addAll(repoAdminMails);
852

  
853
            if (this.override) {
854
                recipients.clear();
855
                recipients.add(overrideEmail);
856
            }
857
            if (!logonly)
858
                mailLibrary.sendEmail(recipients.toArray(new String[]{}), subject, message);
859
            LOGGER.debug("Sending mail to Recipients: " + recipients + " Subject: " + subject + " Message: " + message);
860
        } catch (Exception e) {
861
            LOGGER.error("Error sending mail to Recipients: " + recipients + " Subject: " + subject + " Message: " + message, e);
862
            throw new Exception(e);
863
        }
864
    }
865

  
866
    private String getEmailProperty(String key) {
867
        return pLoader.getProperties().getProperty(key);
868
    }
869

  
870
    public void setSpecialRecipients(String specialRecipients) {
871
        String[] recps = specialRecipients.split(",");
872

  
873
        for (String recp : recps) {
874
            recp = recp.trim();
875

  
876
            this.specialRecipients.add(recp);
877
        }
878
    }
879

  
880

  
881
    public void setOverride(boolean override) {
882
        this.override = override;
883
    }
884

  
885
    public void setOverrideEmail(String overrideEmail) {
886
        this.overrideEmail = overrideEmail;
887
    }
888

  
889
    public String getFrom() {
890
        return from;
891
    }
892

  
893
    public void setFrom(String from) {
894
        this.from = from;
895
    }
896

  
897
    public boolean isLogonly() {
898
        return logonly;
899
    }
900

  
901
    public void setLogonly(boolean logonly) {
902
        this.logonly = logonly;
903
    }
904

  
905
}
modules/uoa-repository-manager-service/tags/release-2.0.0/src/main/java/eu/dnetlib/repo/manager/service/EmailUtils.java
1
package eu.dnetlib.repo.manager.service;
2

  
3
import eu.dnetlib.domain.data.PiwikInfo;
4
import eu.dnetlib.domain.data.Repository;
5
import eu.dnetlib.domain.data.RepositoryInterface;
6
import eu.dnetlib.domain.functionality.validator.JobForValidation;
7
import org.springframework.security.core.Authentication;
8

  
9
public interface EmailUtils {
10

  
11

  
12
    void reportException(Exception exception);
13

  
14
    void sendAdministratorRequestToEnableMetrics(PiwikInfo piwikInfo) throws Exception;
15

  
16
    void sendUserRequestToEnableMetrics(PiwikInfo piwikInfo) throws Exception;
17

  
18
    void sendAdministratorMetricsEnabled(PiwikInfo piwikInfo) throws Exception;
19

  
20
    void sendUserMetricsEnabled(PiwikInfo piwikInfo) throws Exception;
21

  
22
    /****USER REGISTRATION REQUEST EMAILS****/
23
    void sendAdminRegistrationEmail(Repository repository, Authentication authentication) throws Exception;
24

  
25
    void sendUserRegistrationEmail(Repository repository, Authentication authentication) throws Exception;
26

  
27
    void sendAdminRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception;
28

  
29
    void sendUserRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception;
30

  
31
    /****SUCCESSFUL REGISTRATION RESULTS EMAILS****/
32
    void sendUserRegistrationResultsSuccessEmail(String issuerEmail, String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception;
33

  
34
    void sendAdminRegistrationResultsSuccessEmail(String issuerEmail, String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception;
35

  
36
    /****FAILURE REGISTRATION RESULTS EMAILS****/
37
    void sendUserRegistrationResultsFailureEmail(String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception;
38

  
39
    void sendAdminRegistrationResultsFailureEmail(String issuerEmail, String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception;
40

  
41
    /****SUCCESSFUL UPDATE RESULTS EMAILS****/
42
    void sendUserUpdateResultsSuccessEmail(String issuer, String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception;
43

  
44
    void sendAdminUpdateResultsSuccessEmail(String issuerEmail, String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception;
45

  
46
    /****FAILURE UPDATE RESULTS EMAILS****/
47
    void sendUserUpdateResultsFailureEmail(String issuer, String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception;
48

  
49
    void sendAdminUpdateResultsFailureEmail(String issuerEmail, String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception;
50

  
51
    /****VALIDATION OF CONTENT PROVIDER EMAILS****/
52
    void sendUserValidationResults(String issuer,String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception;
53

  
54
    void sendAdminValidationResults(String issuer,String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception;
55

  
56
    /****GENERAL FAILURE OF VALIDATOR****/
57
    void sendAdminGeneralFailure(String issuer,String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception;
58

  
59

  
60
    void sendAdminUpdateRepositoryInfoEmail(Repository repository, Authentication authentication) throws Exception;
61

  
62
    void sendUserUpdateRepositoryInfoEmail(Repository repository, Authentication authentication) throws Exception;
63

  
64
    void sendAdminUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception;
65

  
66
    void sendUserUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception;
67

  
68
    void sendSubmitJobForValidationEmail(Authentication authentication, JobForValidation jobForValidation) throws Exception;
69

  
70
    void sendUponJobCompletion(String repoId,
71
                               String repoInterfaceId,
72
                               int scoreUsage,
73
                               int scoreContent,
74
                               boolean isSuccess,
75
                               boolean isUpdate,
76
                               String issuerEmail,
77
                               String jobId) throws Exception;
78
}
modules/uoa-repository-manager-service/tags/release-2.0.0/src/main/java/eu/dnetlib/repo/manager/service/ValidatorService.java
1
package eu.dnetlib.repo.manager.service;
2

  
3
import eu.dnetlib.api.functionality.ValidatorServiceException;
4
import eu.dnetlib.domain.functionality.validator.JobForValidation;
5
import eu.dnetlib.domain.functionality.validator.RuleSet;
6
import eu.dnetlib.domain.functionality.validator.StoredJob;
7
import eu.dnetlib.repo.manager.domain.InterfaceInformation;
8
import eu.dnetlib.repo.manager.domain.ValidationServiceException;
9
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
10
import org.json.JSONException;
11
import org.springframework.http.ResponseEntity;
12

  
13
import java.util.List;
14

  
15

  
16

  
17
public interface ValidatorService {
18

  
19

  
20
    JobForValidation submitJobForValidation(JobForValidation jobForValidation) throws ValidatorServiceException;
21

  
22
    ResponseEntity<Object> reSubmitJobForValidation(String email, String jobId) throws JSONException, ValidatorServiceException;
23

  
24
    List<RuleSet> getRuleSets(String mode);
25

  
26
    List<String> getSetsOfRepository(String url);
27

  
28
    boolean identifyRepo(String url);
29

  
30
    RuleSet getRuleSet(String acronym);
31

  
32
    List<StoredJob> getStoredJobsNew(String user,
33
                                     String jobType,
34
                                     String offset,
35
                                     String limit,
36
                                     String dateFrom,
37
                                     String dateTo,
38
                                     String validationStatus) throws ValidatorServiceException;
39

  
40
    int getStoredJobsTotalNumberNew(String user, String jobType, String validationStatus) throws ValidatorServiceException;
41

  
42
    InterfaceInformation getInterfaceInformation(String baseUrl) throws ValidationServiceException;
43

  
44
    List<StoredJob> getJobsSummary(String repoId, int limit) throws ValidatorServiceException, ResourceNotFoundException, JSONException;
45
}
modules/uoa-repository-manager-service/tags/release-2.0.0/src/main/java/eu/dnetlib/repo/manager/service/MonitorService.java
1
package eu.dnetlib.repo.manager.service;
2

  
3
import eu.dnetlib.api.functionality.ValidatorServiceException;
4
import eu.dnetlib.domain.functionality.validator.StoredJob;
5
import eu.dnetlib.repo.manager.domain.JobsOfUser;
6
import org.json.JSONException;
7

  
8

  
9
public interface MonitorService {
10

  
11

  
12
    JobsOfUser getJobsOfUser(String user,
13
                             String jobType,
14
                             String offset,
15
                             String limit,
16
                             String dateFrom,
17
                             String dateTo,
18
                             String validationStatus,
19
                             String includeJobsTotal) throws JSONException, ValidatorServiceException;
20

  
21
    int getJobsOfUserPerValidationStatus(String user,
22
                                         String jobType,
23
                                         String validationStatus) throws JSONException;
24

  
25

  
26
    StoredJob getJobSummary(String jobId,
27
                            String groupBy) throws JSONException;
28

  
29
}
modules/uoa-repository-manager-service/tags/release-2.0.0/src/main/java/eu/dnetlib/repo/manager/service/customHystrixCommands/AggregatorsHystrixCommand.java
1
package eu.dnetlib.repo.manager.service.customHystrixCommands;
2

  
3
import com.netflix.hystrix.HystrixCommand;
4
import com.netflix.hystrix.HystrixCommandGroupKey;
5
import org.springframework.http.HttpMethod;
6
import org.springframework.http.ResponseEntity;
7
import org.springframework.web.client.RestTemplate;
8
import org.springframework.web.util.UriComponents;
9
import org.springframework.web.util.UriComponentsBuilder;
10

  
11
import java.util.Map;
12

  
13
public class AggregatorsHystrixCommand extends HystrixCommand<String> {
14

  
15
    RestTemplate restTemplate;
16
    String baseAddress;
17

  
18
    public AggregatorsHystrixCommand(String baseAddress, RestTemplate restTemplate) {
19
        super(HystrixCommandGroupKey.Factory.asKey("StatisticsGroup"));
20
        this.baseAddress = baseAddress;
21
        this.restTemplate = restTemplate;
22
    }
23

  
24
    @Override
25
    protected String run() throws Exception {
26
        String url = baseAddress + "/resources" +
27
                "?query= " +
28
                " oaftype exact datasource and " +
29
                " ( datasourcetypename exact Institutional Repository Aggregator " +
30
                "     or datasourcetypename exact Publication Repository Aggregator )";
31

  
32
        UriComponents uriComponents = UriComponentsBuilder
33
                .fromHttpUrl(url)
34
                .queryParam("page", 0)
35
                .queryParam("size", 0)
36
                .queryParam("format", "json")
37
                .build().encode();
38

  
39
        ResponseEntity rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
40
        Map metadata = (Map) ((Map) rs.getBody()).get("meta");
41
        return String.valueOf(metadata.get("total"));
42
    }
43

  
44
    @Override
45
    protected String getFallback() {
46
        return null;
47
    }
48
}
modules/uoa-repository-manager-service/tags/release-2.0.0/src/main/java/eu/dnetlib/repo/manager/service/customHystrixCommands/LastYearUsageStatsHystrixCommand.java
1
package eu.dnetlib.repo.manager.service.customHystrixCommands;
2

  
3
import com.netflix.hystrix.HystrixCommand;
4
import com.netflix.hystrix.HystrixCommandGroupKey;
5
import org.springframework.http.HttpMethod;
6
import org.springframework.http.ResponseEntity;
7
import org.springframework.web.client.RestTemplate;
8
import org.springframework.web.util.UriComponents;
9
import org.springframework.web.util.UriComponentsBuilder;
10

  
11
import java.util.HashMap;
12
import java.util.List;
13
import java.util.Map;
14

  
15
public class LastYearUsageStatsHystrixCommand extends HystrixCommand<Map> {
16

  
17
    RestTemplate restTemplate;
18
    String usagestatsBaseAddress;
19

  
20
    public LastYearUsageStatsHystrixCommand(String usagestatsBaseAddress,RestTemplate restTemplate) {
21
        super(HystrixCommandGroupKey.Factory.asKey("StatisticsGroup"));
22
        this.usagestatsBaseAddress = usagestatsBaseAddress;
23
        this.restTemplate = restTemplate;
24
    }
25

  
26
    @Override
27
    protected Map run() throws Exception {
28
        UriComponents uriComponents = UriComponentsBuilder
29
                .fromHttpUrl(usagestatsBaseAddress + "/totals")
30
                .build().encode();
31

  
32
        ResponseEntity rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET,null,Map.class);
33

  
34
        List yearly_stats = (List) ((Map)rs.getBody()).get("yearly_stats");
35
        Map lastYear = (Map) yearly_stats.get(yearly_stats.size()-1);
36
        Integer downloads = (Integer) lastYear.get("downloads");
37
        Integer views = (Integer) lastYear.get("views");
38
        Integer year = (Integer) lastYear.get("year");
39

  
40
        Map<String,Object> usagestats = new HashMap<>();
41
        usagestats.put("number",String.valueOf(downloads+views));
42
        usagestats.put("year",year);
43

  
44
        return usagestats;
45
    }
46

  
47
    @Override
48
    protected Map getFallback() {
49
        return null;
50
    }
51

  
52
}
modules/uoa-repository-manager-service/tags/release-2.0.0/src/main/java/eu/dnetlib/repo/manager/service/StatsServiceImpl.java
1
package eu.dnetlib.repo.manager.service;
2

  
3
import eu.dnetlib.repo.manager.service.customHystrixCommands.*;
4
import org.springframework.beans.factory.annotation.Autowired;
5
import org.springframework.beans.factory.annotation.Value;
6
import org.springframework.stereotype.Service;
7
import org.springframework.web.client.RestTemplate;
8

  
9
import java.util.HashMap;
10
import java.util.Map;
11

  
12
@Service("statsService")
13
public class StatsServiceImpl implements StatsService {
14

  
15
    @Autowired
16
    RestTemplate restTemplate;
17

  
18
    @Value("${search.api.baseAddress}")
19
    private String baseAddress;
20
    @Value("${search.api.usagestats}")
21
    private String usagestatsBaseAddress;
22
    @Value("${search.api.usageEvents}")
23
    private String usagestatsEvents;
24

  
25
    @Override
26
    public Map getStatistics()  {
27

  
28
        UsageStatsTotalHystrixCommand usageStatsTotalHystrixCommand = new UsageStatsTotalHystrixCommand(usagestatsEvents,restTemplate);
29
        DataRepositoriesHystrixCommand dataRepositoriesHystrixCommand = new DataRepositoriesHystrixCommand(baseAddress,restTemplate);
30
        AggregatorsHystrixCommand aggregatorsHystrixCommand = new AggregatorsHystrixCommand(baseAddress,restTemplate);
31
        LiteratureHystrixCommand literatureHystrixCommand = new LiteratureHystrixCommand(baseAddress,restTemplate);
32
        JournalHystrixCommand journalHystrixCommand = new JournalHystrixCommand(baseAddress,restTemplate);
33
        PublicationHystrixCommand publicationHystrixCommand = new PublicationHystrixCommand(baseAddress,restTemplate);
34
        DatasetsHystrixCommand datasetsHystrixCommand = new DatasetsHystrixCommand(baseAddress,restTemplate);
35
        SoftwareHystrixCommand softwareHystrixCommand = new SoftwareHystrixCommand(baseAddress,restTemplate);
36
        LastYearUsageStatsHystrixCommand lastYearUsageStatsHystrixCommand = new LastYearUsageStatsHystrixCommand(usagestatsBaseAddress,restTemplate);
37

  
38
        Map<String,Object> stats = new HashMap<>();
39
        stats.put("aggregators",aggregatorsHystrixCommand.execute());
40
        stats.put("dataRepositories",dataRepositoriesHystrixCommand.execute());
41
        stats.put("literature",literatureHystrixCommand.execute());
42
        stats.put("journal",journalHystrixCommand.execute());
43
        stats.put("publications",publicationHystrixCommand.execute());
44
        stats.put("datasets",datasetsHystrixCommand.execute());
45
        stats.put("software",softwareHystrixCommand.execute());
46
        stats.put("lastYearUsagestats", lastYearUsageStatsHystrixCommand.execute());
47
        stats.put("usagestats",usageStatsTotalHystrixCommand.execute());
48
        return stats;
49
    }
50
}
modules/uoa-repository-manager-service/tags/release-2.0.0/src/main/java/eu/dnetlib/repo/manager/service/customHystrixCommands/DatasetsHystrixCommand.java
1
package eu.dnetlib.repo.manager.service.customHystrixCommands;
2

  
3
import com.netflix.hystrix.HystrixCommand;
4
import com.netflix.hystrix.HystrixCommandGroupKey;
5
import org.springframework.http.HttpMethod;
6
import org.springframework.http.ResponseEntity;
7
import org.springframework.web.client.RestTemplate;
8
import org.springframework.web.util.UriComponents;
9
import org.springframework.web.util.UriComponentsBuilder;
10

  
11
import java.util.Map;
12

  
13
public class DatasetsHystrixCommand extends HystrixCommand<String> {
14

  
15
    RestTemplate restTemplate;
16
    String baseAddress;
17

  
18
    public DatasetsHystrixCommand(String baseAddress,RestTemplate restTemplate) {
19
        super(HystrixCommandGroupKey.Factory.asKey("StatisticsGroup"));
20
        this.restTemplate = restTemplate;
21
        this.baseAddress = baseAddress;
22
    }
23

  
24
    @Override
25
    protected String run() throws Exception {
26
        String url = baseAddress+"/datasets/count";
27

  
28
        UriComponents uriComponents = UriComponentsBuilder
29
                .fromHttpUrl(url)
30
                .queryParam("page", 0)
31
                .queryParam("size", 0)
32
                .queryParam("format", "json")
33
                .build().encode();
34

  
35
        ResponseEntity rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
36
        Map metadata = (Map) (rs.getBody());
37
        return String.valueOf(metadata.get("total"));
38
    }
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff