Project

General

Profile

« Previous | Next » 

Revision 52363

1. Update version in scripts and pom.
2. Bug fix in 'init_db' script (remove a new line).
3. Functionality for sending an email to a parametrized list of users added (EmailSender.java).
4. Add a POST method in API that gets a list of recipients and sends them an email (/invite - EmailController.java).
5. Add properties for EmailSender (need to be overrided in override.properties file).
6. Add in pom.xml dependencies for EmailSender.

View differences:

modules/uoa-admin-tools/update_db.js
1
//version compatibility: 1.0.1-SNAPSHOT
1
//version compatibility: 1.1.0-SNAPSHOT
2 2

  
3 3
function updateStats(){
4 4
    print("Update Stats...")
modules/uoa-admin-tools/init_db.js
1
//version compatibility: 1.0.1-SNAPSHOT
1
//version compatibility: 1.1.0-SNAPSHOT
2 2
print("here");
3 3

  
4 4
function dropDB(){
......
82 82
	db.page.save({"name" : "About", "route" : "/about", "type" : "html", "connect":true,"openaire":false,"entities" : []})
83 83
	db.page.save({"name" : "Organizations", "route" : "/organizations", "type" : "html", "connect":true,"openaire":false,"entities" : []})
84 84

  
85

  
86 85
    link = db.page.find( { route: "/participate/claim" }).map( function(page) { return page._id.str; } ).toString()
87 86
	directLink = db.page.find( { route: "/participate/direct-claim" }).map( function(page) { return page._id.str; } ).toString()
88 87

  
......
164 163
	community_pages[searchDatasets] = true;
165 164
	community_pages[searchSoftware] = true;
166 165
	community_pages[searchProject] = true;
167
	community_pages[searchOrganization] = true;	
166
	community_pages[searchOrganization] = true;
168 167
	community_pages[searchDataprovider] = true;
169 168
	community_pages[advancedSearchPublications] = true;
170
	community_pages[advancedSearchDatasets] = true; 
169
	community_pages[advancedSearchDatasets] = true;
171 170
	community_pages[advancedSearchSoftware] = true;
172 171
	community_pages[advancedSearchProject] = true;
173 172
	community_pages[advancedSearchOrganization] = true;
174 173
	community_pages[advancedSearchDataprovider] = true;
175 174
	community_pages[searchJournals] = true;
176
	community_pages[searchEntityRegistries] = true; 
175
	community_pages[searchEntityRegistries] = true;
177 176
	community_pages[searchContentProviders] = true;
178 177
	community_pages[searchJournalsTable] = true;
179 178
	community_pages[searchEntityRegistriesTable] = true;
180
	community_pages[searchContentProvidersTable] = true; 
181
	community_pages[depositPublications] = true;	
179
	community_pages[searchContentProvidersTable] = true;
180
	community_pages[depositPublications] = true;
182 181
	community_pages[depositDatasets] = true;
183 182
	community_pages[depositPublicationsResults] = true;
184 183
	community_pages[depositDatasetsResults] = true;
......
296 295
createCollections();
297 296
initializeEntitiesPagesDivIds();
298 297
//createCommunity("OpenAIRE","openaire");
299
 createAllCommunities();
298
createAllCommunities();
300 299
addDefaultHtmlToHtmlPages();
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/controllers/EmailController.java
1
package eu.dnetlib.uoaadmintools.controllers;
2

  
3
import eu.dnetlib.uoaadmintools.emailSender.EmailSender;
4
import org.apache.log4j.Logger;
5
import org.springframework.beans.factory.annotation.Autowired;
6
import org.springframework.web.bind.annotation.*;
7

  
8
import java.util.List;
9

  
10
@RestController
11
@CrossOrigin(origins = "*")
12
public class EmailController {
13
    private final Logger log = Logger.getLogger(this.getClass());
14

  
15
    @Autowired
16
    private EmailSender emailSender;
17

  
18
    @RequestMapping(value = "/invite", method = RequestMethod.POST)
19
    public Boolean inviteReciptients(@RequestBody List<String> reciptients) throws Exception {
20
        emailSender.send(reciptients);
21
        return true;
22
    }
23
}
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/emailSender/EmailSender.java
1
package eu.dnetlib.uoaadmintools.emailSender;
2

  
3
import org.apache.log4j.Logger;
4
import org.hibernate.validator.constraints.Email;
5
import org.springframework.beans.factory.annotation.Autowired;
6
import org.springframework.beans.factory.annotation.Configurable;
7
import org.springframework.beans.factory.annotation.Value;
8
import org.springframework.boot.context.properties.ConfigurationProperties;
9
import org.springframework.context.annotation.Bean;
10
import org.springframework.stereotype.*;
11
import org.springframework.stereotype.Service;
12
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
13

  
14
import javax.mail.*;
15
import javax.mail.internet.AddressException;
16
import javax.mail.internet.InternetAddress;
17
import javax.mail.internet.MimeMessage;
18
import java.text.SimpleDateFormat;
19
import java.util.*;
20

  
21
@Service
22
@Configurable
23
public class EmailSender {
24

  
25
    private static final Logger logger = Logger.getLogger(EmailSender.class);
26

  
27
    @Value( "${admintool.username}" )
28
    private String username = null;
29
    @Value( "${admintool.password}" )
30
    private String password = null;
31
    @Value( "${admintool.host}" )
32
    private String host = null;
33
    @Value( "${admintool.port}" )
34
    private String port = null;
35
    @Value( "${admintool.from}" )
36
    private String from = null;
37

  
38
    public void send(List<String> recipients) {
39
        // Get system properties
40
        Properties properties = System.getProperties();
41
        properties.setProperty("mail.smtp.host", host);
42
        properties.put("mail.smtp.port", port);
43
        properties.put("mail.smtp.auth", "true"); //enable authentication
44
        properties.put("mail.smtp.starttls.enable", "true");
45

  
46
        Session session = Session.getInstance(properties,
47
                new javax.mail.Authenticator() {
48
                    protected PasswordAuthentication getPasswordAuthentication() {
49
                        return new PasswordAuthentication(username, password);
50
                    }
51
                });
52

  
53
        try {
54
            // Create a default MimeMessage object.
55
            MimeMessage message = new MimeMessage(session);
56

  
57
            // Set From: header field of the header.
58
            message.setFrom(new InternetAddress(from));
59

  
60
            // Set To: header field of the header.
61
            for(String to : recipients) {
62
                message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
63
            }
64

  
65
            // Set Subject: header field
66
            message.setSubject("Openaire Claims Notification");
67

  
68
            // For simple text setText() can be used instead of setContent()
69

  
70
            // Send the actual HTML message, as big as you like
71
            message.setContent("Test email", "text/html");
72

  
73
            // Send message
74
            Transport.send(message);
75
            logger.debug("Sent message successfully....\n");
76

  
77
        } catch (AddressException ae) {
78
            logger.error("Email could not be send.", ae);
79

  
80
        } catch (MessagingException me) {
81
            logger.error("Email could not be send.", me);
82
        }
83
    }
84

  
85
}
modules/uoa-admin-tools/src/main/resources/admintools.properties
3 3
admintool.originServer = .di.uoa.gr
4 4
#beta
5 5
#admintool.userInfoUrl =  https://beta.services.openaire.eu/uoa-user-management/api/users/getUserInfo?accessToken=
6
#admintool.originServer = .openaire.eu
6
#admintool.originServer = .openaire.eu
7

  
8
admintool.host = smtp.gmail.com
9
admintool.port = 587
10
admintool.from = invalid_email@email.com
11
admintool.username = invalid_email@email.com
12
admintool.password = invalid_password
modules/uoa-admin-tools/pom.xml
5 5

  
6 6
	<groupId>eu.dnetlib</groupId>
7 7
	<artifactId>uoa-admin-tools</artifactId>
8
	<version>1.0.1-SNAPSHOT</version>
8
	<version>1.1.0-SNAPSHOT</version>
9 9
	<packaging>war</packaging>
10 10

  
11 11
	<name>uoa-admin-tools</name>
......
60 60
			<artifactId>gson</artifactId>
61 61
			<version>2.8.2</version>
62 62
		</dependency>
63
        <dependency>
64
            <groupId>javax.mail</groupId>
65
            <artifactId>mail</artifactId>
66
            <version>1.5.0-b01</version>
67
        </dependency>
68
        <dependency>
69
            <groupId>commons-io</groupId>
70
            <artifactId>commons-io</artifactId>
71
            <version>20030203.000550</version>
72
        </dependency>
63 73

  
64 74
	</dependencies>
65 75

  

Also available in: Unified diff