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

Change-Id: I41eea78cf1fb19b44f46411e25ecb27b52c74982
diff --git a/full/Changes b/full/Changes
index 40a067f..7d83752 100644
--- a/full/Changes
+++ b/full/Changes
@@ -1,3 +1,10 @@
+version 0.60 release
+21/02/2018
+	- set up mail settings using localhost port 25 (margaretha)
+	- added mail template in kustvakt configuration (margaretha)
+	- added mail settings to readme (margaretha)
+	- disabled email notification for auto group (margaretha)
+
 version 0.59.10	
 20/02/2018 
 	- added sort VC by id (margaretha)
@@ -18,6 +25,7 @@
 	- testing mail implementation using embedded jetty jndi (margaretha)
 	- fixed collection rewrite regarding OR operation with other fields (margaretha)
 	- implemented sending mail using spring injection and removed jetty jndi (margaretha)
+	- fixed unrecognized application/json (margaretha)
 	- fixed and updated velocity template (margaretha)
 	
 version 0.59.9 
diff --git a/full/pom.xml b/full/pom.xml
index 1391cc4..b1b92c8 100644
--- a/full/pom.xml
+++ b/full/pom.xml
@@ -3,7 +3,7 @@
 	<modelVersion>4.0.0</modelVersion>
 	<groupId>de.ids_mannheim.korap</groupId>
 	<artifactId>Kustvakt-full</artifactId>
-	<version>0.59.10</version>
+	<version>0.60</version>
 	<properties>
 		<java.version>1.8</java.version>
 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -86,12 +86,12 @@
 			<plugin>
 				<groupId>org.apache.maven.plugins</groupId>
 				<artifactId>maven-surefire-plugin</artifactId>
-				<version>2.19.1</version>
+				<version>2.20.1</version>
 				<configuration>
 					<reuseForks>false</reuseForks>
 					<forkCount>2</forkCount>
 					<threadCount>10</threadCount>
-
+					<argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
 					<excludes>
 						<!-- <exclude>de/ids_mannheim/korap/suites/*.java</exclude> -->
 						<!-- <exclude>de/ids_mannheim/korap/dao/*.java</exclude> -->
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
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerTest.java
index be39d02..c907338 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerTest.java
@@ -472,7 +472,6 @@
                                 "pass"))
                 .entity(userGroup).post(ClientResponse.class);
 
-        String entity = response.getEntity(String.class);
         assertEquals(Status.OK.getStatusCode(), response.getStatus());
 
         // check member
diff --git a/full/src/test/resources/kustvakt-test.conf b/full/src/test/resources/kustvakt-test.conf
index aa76a83..ca6b233 100644
--- a/full/src/test/resources/kustvakt-test.conf
+++ b/full/src/test/resources/kustvakt-test.conf
@@ -10,15 +10,18 @@
 ldap.config = file-path-to-ldap-config
 
 # Kustvakt
-## mail settings
-mail.enabled = false
-mail.receiver = test-email
-mail.sender = noreply@ids-mannheim.de
-
 ## server
 server.port=8089
 server.host=localhost
 
+## mail settings
+mail.enabled = false
+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