Set mail using localhost & added mail template in kustvakt config.

Change-Id: I41eea78cf1fb19b44f46411e25ecb27b52c74982
diff --git a/full/src/main/java/de/ids_mannheim/korap/authentication/KustvaktAuthenticationManager.java b/full/src/main/java/de/ids_mannheim/korap/authentication/KustvaktAuthenticationManager.java
index 564832c..0015e89 100644
--- a/full/src/main/java/de/ids_mannheim/korap/authentication/KustvaktAuthenticationManager.java
+++ b/full/src/main/java/de/ids_mannheim/korap/authentication/KustvaktAuthenticationManager.java
@@ -203,7 +203,6 @@
 
 	@Override
 	public void setAccessAndLocation(User user, HttpHeaders headers) {
-		Boolean DEBUG_LOG = true;
 		MultivaluedMap<String, String> headerMap = headers.getRequestHeaders();
 		Location location = Location.EXTERN;
 		CorpusAccess corpusAccess = CorpusAccess.FREE;
@@ -212,8 +211,7 @@
 	    {
 	    	// to be absolutely sure:
 	    	user.setCorpusAccess(User.CorpusAccess.FREE);
-	    	if( DEBUG_LOG == true )
-	    		System.out.printf("setAccessAndLocation: DemoUser: location=%s, access=%s.\n", user.locationtoString(), user.accesstoString());
+	    	jlog.debug("setAccessAndLocation: DemoUser: location=%s, access=%s.\n", user.locationtoString(), user.accesstoString());
 	     	return;
 	    }
 		
@@ -245,8 +243,8 @@
 
 			user.setLocation(location);
 			user.setCorpusAccess(corpusAccess);
-	    	if( DEBUG_LOG == true )
-	    		System.out.printf("setAccessAndLocation: KorAPUser: location=%s, access=%s.\n", user.locationtoString(), user.accesstoString());
+	    	
+	    	jlog.debug("setAccessAndLocation: KorAPUser: location=%s, access=%s.\n", user.locationtoString(), user.accesstoString());
 
 		}
 	} // getAccess
diff --git a/full/src/main/java/de/ids_mannheim/korap/config/FullConfiguration.java b/full/src/main/java/de/ids_mannheim/korap/config/FullConfiguration.java
index 4d51c4e..201fc4b 100644
--- a/full/src/main/java/de/ids_mannheim/korap/config/FullConfiguration.java
+++ b/full/src/main/java/de/ids_mannheim/korap/config/FullConfiguration.java
@@ -19,6 +19,8 @@
     private String testEmail;
     private String noReply;
 
+    private String groupInvitationTemplate;
+    
     private String ldapConfig;
 
     private String freeOnlyRegex;
@@ -64,6 +66,7 @@
             // other properties must be set in the kustvakt.conf
             setTestEmail(properties.getProperty("mail.receiver"));
             setNoReply(properties.getProperty("mail.sender"));
+            setGroupInvitationTemplate(properties.getProperty("template.group.invitation"));
         }
     }
 
@@ -258,4 +261,12 @@
         this.noReply = noReply;
     }
 
+    public String getGroupInvitationTemplate () {
+        return groupInvitationTemplate;
+    }
+
+    public void setGroupInvitationTemplate (String groupInvitationTemplate) {
+        this.groupInvitationTemplate = groupInvitationTemplate;
+    }
+
 }
diff --git a/full/src/main/java/de/ids_mannheim/korap/service/MailService.java b/full/src/main/java/de/ids_mannheim/korap/service/MailService.java
index ff05bbe..866a0a9 100644
--- a/full/src/main/java/de/ids_mannheim/korap/service/MailService.java
+++ b/full/src/main/java/de/ids_mannheim/korap/service/MailService.java
@@ -17,24 +17,26 @@
 import org.springframework.mail.javamail.MimeMessagePreparator;
 import org.springframework.stereotype.Service;
 
+import de.ids_mannheim.korap.config.FullConfiguration;
 import de.ids_mannheim.korap.interfaces.AuthenticationManagerIface;
 import de.ids_mannheim.korap.user.User;
 
 @Service
 public class MailService {
-    
-    private static Logger jlog =
-            LoggerFactory.getLogger(MailService.class);
-    
+
+    private static Logger jlog = LoggerFactory.getLogger(MailService.class);
+
     @Autowired
     private AuthenticationManagerIface authManager;
     @Autowired
     private JavaMailSender mailSender;
     @Autowired
     private VelocityEngine velocityEngine;
+    @Autowired
+    private FullConfiguration config;
 
     public void sendMemberInvitationNotification (String inviteeName,
-            String sender, String groupName, String inviter) {
+            String groupName, String inviter) {
 
         MimeMessagePreparator preparator = new MimeMessagePreparator() {
 
@@ -44,28 +46,29 @@
 
                 MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
                 message.setTo(new InternetAddress(invitee.getEmail()));
-                message.setFrom(sender);
-                message.setSubject("Invitation to join "+groupName);
-                message.setText(prepareText(inviteeName, groupName, inviter),
-                        true);
+                message.setFrom(config.getNoReply());
+                message.setSubject("Invitation to join " + groupName);
+                message.setText(prepareGroupInvitationText(inviteeName,
+                        groupName, inviter), true);
             }
 
         };
         mailSender.send(preparator);
     }
 
-    private String prepareText (String username, String groupName,
-            String inviter) {
+    private String prepareGroupInvitationText (String username,
+            String groupName, String inviter) {
         Context context = new VelocityContext();
         context.put("username", username);
         context.put("group", groupName);
         context.put("inviter", inviter);
-        
+
         StringWriter stringWriter = new StringWriter();
-        
-        velocityEngine.mergeTemplate("templates/notification.vm",
+
+        velocityEngine.mergeTemplate(
+                "templates/" + config.getGroupInvitationTemplate(),
                 StandardCharsets.UTF_8.name(), context, stringWriter);
-        
+
         String message = stringWriter.toString();
         jlog.debug(message);
         return message;
diff --git a/full/src/main/java/de/ids_mannheim/korap/service/UserGroupService.java b/full/src/main/java/de/ids_mannheim/korap/service/UserGroupService.java
index d1c9c84..9c3e245 100644
--- a/full/src/main/java/de/ids_mannheim/korap/service/UserGroupService.java
+++ b/full/src/main/java/de/ids_mannheim/korap/service/UserGroupService.java
@@ -250,9 +250,8 @@
         member.setUserId(username);
         groupMemberDao.addMember(member);
 
-        if (config.isMailEnabled()) {
-            mailService.sendMemberInvitationNotification(username,
-                    config.getNoReply(), userGroup.getName(), createdBy);
+        if (config.isMailEnabled() && userGroup.getStatus() != UserGroupStatus.HIDDEN) {
+            mailService.sendMemberInvitationNotification(username,userGroup.getName(), createdBy);
         }
     }
 
diff --git a/full/src/main/resources/kustvakt.conf b/full/src/main/resources/kustvakt.conf
index edb1bce..d737a06 100644
--- a/full/src/main/resources/kustvakt.conf
+++ b/full/src/main/resources/kustvakt.conf
@@ -16,9 +16,12 @@
 
 ## mail settings
 mail.enabled = false
-mail.receiver = test-email
+mail.receiver = test@localhost
 mail.sender = noreply@ids-mannheim.de
 
+## mail.templates
+template.group.invitation = notification.vm
+
 ## default layers
 default.layer.p = tt
 default.layer.l = tt
diff --git a/full/src/main/resources/properties/mail.properties b/full/src/main/resources/properties/mail.properties
index 492b322..29d1ca1 100644
--- a/full/src/main/resources/properties/mail.properties
+++ b/full/src/main/resources/properties/mail.properties
@@ -1,7 +1,7 @@
-mail.host = smtp.host
+mail.host = localhost
 mail.port = 25
 mail.connectiontimeout = 3000
-mail.auth = true
-mail.starttls.enable = true
+mail.auth = false
+mail.starttls.enable = false
 mail.username = username
 mail.password = password
\ No newline at end of file