// Path: src/main/java/com/jipasoft/task/AsyncMailSender.java
// public class AsyncMailSender extends JavaMailSenderImpl {
// 
// 	@Async
// 	@Override
// 	public void send(SimpleMailMessage simpleMessage) throws MailException {
// 		super.send(simpleMessage);
// 	}
// 
// 	@Async
// 	@Override
// 	public void send(SimpleMailMessage... simpleMessages) throws MailException {
// 		super.send(simpleMessages);
// 	}
// }
// 
// Path: src/main/java/com/jipasoft/task/ExceptionAspect.java
// @Slf4j
// @Aspect
// @Component
// public class ExceptionAspect {
// 
// 	@Inject
// 	private MailSender mailSender;
// 	@Value("${spring.user.email}")
// 	private String[] to;
// 
// 	@Pointcut("within(com.jipasoft.web..*)")
// 	public void mailingPointcut() {
// 	}
// 
// 	@AfterThrowing(pointcut = "mailingPointcut()", throwing = "e")
// 	public void mailAfterThrowing(JoinPoint joinPoint, Throwable e) {
// 		// @formatter:off
// 		// Building stack trace string
// 		StringWriter stackTrace = new StringWriter();
// 		e.printStackTrace(new PrintWriter(stackTrace));
// 		// Building e-mail
// 		SimpleMailMessage email = new SimpleMailMessage();
// 		email.setTo(to);
// 		email.setSubject("[Spring Profiles Aspect] Exception in '" + joinPoint.getSignature().getName() + "' method");
// 		email.setText(
// 			"Exception in: " + joinPoint.getSignature().getName() + "\n\n" +
// 			"Class: " + joinPoint.getSignature().getDeclaringTypeName()  + "\n\n" +
// 			"Time: " + ZonedDateTime.now() + "\n\n" +
// 			"Message: " + e.getMessage() + "\n\n" +
// 			"StackTrace:\n" + stackTrace.getBuffer().toString()
// 		);
// 		// Sending e-mail
// 		try {
// 			this.mailSender.send(email);
// 		} catch (MailException mailException) {
// 			log.error(mailException.getMessage());
// 		}
// 	}
// }
// 
// Path: src/main/java/com/jipasoft/task/ExceptionInterceptor.java
// @Slf4j
// public class ExceptionInterceptor implements MethodInterceptor {
// 	@Inject
// 	private MailSender mailSender;
// 	@Value("${spring.user.email}")
// 	private String[] to;
// 
// 	@Override
// 	public Object invoke(MethodInvocation method) throws Throwable {
// 		Object result = null;
// 		try {
// 			result = method.proceed();
// 		} catch (Exception e) {
// 			// @formatter:off
// 			// Building stack trace string
// 			StringWriter stackTrace = new StringWriter();
// 			e.printStackTrace(new PrintWriter(stackTrace));
// 			// Building e-mail
// 			SimpleMailMessage email = new SimpleMailMessage();
// 			email.setTo(to);
// 			email.setSubject("[Spring Profiles] Exception in '" + method.getMethod().getName() + "' method");
// 			email.setText(
// 				"Exception in: " + method.getMethod().getName() + "\n\n" +
// 				"Class: " + method.getMethod().getDeclaringClass().getName() + "\n\n" +
// 				"Time: " + ZonedDateTime.now() + "\n\n" +
// 				"Message: " + e.getMessage() + "\n\n" +
// 				"StackTrace:\n" + stackTrace.getBuffer().toString()
// 			);
// 			// Sending e-mail
// 			try {
// 				this.mailSender.send(email);
// 			} catch (MailException mailException) {
// 				log.error(mailException.getMessage());
// 			}
// 			throw e;
// 			// @formatter:on
// 
// 		}
// 		return result;
// 	}
// }
// 
// Path: src/main/java/com/jipasoft/util/Profiles.java
// public class Profiles {
// 	public static final String H2 = "h2";
// 	public static final String POSTGRES = "postgres";
// 	public static final String MYSQL = "mysql";
// 	public static final String MONGO = "mongo";
// 	public static final String EMAIL = "email";
// 	public static final String HEROKU = "heroku";
// 	public static final String ASPECT = "aspect";
// }


import com.jipasoft.task.AsyncMailSender;
import com.jipasoft.task.ExceptionAspect;
import com.jipasoft.task.ExceptionInterceptor;
import com.jipasoft.util.Profiles;
import java.util.Map;
import java.util.Properties;
import javax.inject.Inject;
import org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator;
import org.springframework.boot.autoconfigure.mail.MailProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
/*
* Copyright 2016, Julius Krah
* by the @authors tag. See the LICENCE in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jipasoft.config;





/**
 * Configures asynchronous mailing When an exception is encountered in the
 * application, it will send an email to the developer.<br />
 * It may also send the <i>Stacktrace</i> of the error depending on the
 * configured property of the application.<br />
 * <p>
 * 
 * The application's email feature can be enabled when the {@code aspect}
 * profile is active.
 * </p>
 * 
 * @author Julius Krah
 *
 */
@EnableAsync
@Profile(Profiles.ASPECT)
@Configuration
// Path: src/main/java/com/jipasoft/task/AsyncMailSender.java
// public class AsyncMailSender extends JavaMailSenderImpl {
// 
// 	@Async
// 	@Override
// 	public void send(SimpleMailMessage simpleMessage) throws MailException {
// 		super.send(simpleMessage);
// 	}
// 
// 	@Async
// 	@Override
// 	public void send(SimpleMailMessage... simpleMessages) throws MailException {
// 		super.send(simpleMessages);
// 	}
// }
// 
// Path: src/main/java/com/jipasoft/task/ExceptionAspect.java
// @Slf4j
// @Aspect
// @Component
// public class ExceptionAspect {
// 
// 	@Inject
// 	private MailSender mailSender;
// 	@Value("${spring.user.email}")
// 	private String[] to;
// 
// 	@Pointcut("within(com.jipasoft.web..*)")
// 	public void mailingPointcut() {
// 	}
// 
// 	@AfterThrowing(pointcut = "mailingPointcut()", throwing = "e")
// 	public void mailAfterThrowing(JoinPoint joinPoint, Throwable e) {
// 		// @formatter:off
// 		// Building stack trace string
// 		StringWriter stackTrace = new StringWriter();
// 		e.printStackTrace(new PrintWriter(stackTrace));
// 		// Building e-mail
// 		SimpleMailMessage email = new SimpleMailMessage();
// 		email.setTo(to);
// 		email.setSubject("[Spring Profiles Aspect] Exception in '" + joinPoint.getSignature().getName() + "' method");
// 		email.setText(
// 			"Exception in: " + joinPoint.getSignature().getName() + "\n\n" +
// 			"Class: " + joinPoint.getSignature().getDeclaringTypeName()  + "\n\n" +
// 			"Time: " + ZonedDateTime.now() + "\n\n" +
// 			"Message: " + e.getMessage() + "\n\n" +
// 			"StackTrace:\n" + stackTrace.getBuffer().toString()
// 		);
// 		// Sending e-mail
// 		try {
// 			this.mailSender.send(email);
// 		} catch (MailException mailException) {
// 			log.error(mailException.getMessage());
// 		}
// 	}
// }
// 
// Path: src/main/java/com/jipasoft/task/ExceptionInterceptor.java
// @Slf4j
// public class ExceptionInterceptor implements MethodInterceptor {
// 	@Inject
// 	private MailSender mailSender;
// 	@Value("${spring.user.email}")
// 	private String[] to;
// 
// 	@Override
// 	public Object invoke(MethodInvocation method) throws Throwable {
// 		Object result = null;
// 		try {
// 			result = method.proceed();
// 		} catch (Exception e) {
// 			// @formatter:off
// 			// Building stack trace string
// 			StringWriter stackTrace = new StringWriter();
// 			e.printStackTrace(new PrintWriter(stackTrace));
// 			// Building e-mail
// 			SimpleMailMessage email = new SimpleMailMessage();
// 			email.setTo(to);
// 			email.setSubject("[Spring Profiles] Exception in '" + method.getMethod().getName() + "' method");
// 			email.setText(
// 				"Exception in: " + method.getMethod().getName() + "\n\n" +
// 				"Class: " + method.getMethod().getDeclaringClass().getName() + "\n\n" +
// 				"Time: " + ZonedDateTime.now() + "\n\n" +
// 				"Message: " + e.getMessage() + "\n\n" +
// 				"StackTrace:\n" + stackTrace.getBuffer().toString()
// 			);
// 			// Sending e-mail
// 			try {
// 				this.mailSender.send(email);
// 			} catch (MailException mailException) {
// 				log.error(mailException.getMessage());
// 			}
// 			throw e;
// 			// @formatter:on
// 
// 		}
// 		return result;
// 	}
// }
// 
// Path: src/main/java/com/jipasoft/util/Profiles.java
// public class Profiles {
// 	public static final String H2 = "h2";
// 	public static final String POSTGRES = "postgres";
// 	public static final String MYSQL = "mysql";
// 	public static final String MONGO = "mongo";
// 	public static final String EMAIL = "email";
// 	public static final String HEROKU = "heroku";
// 	public static final String ASPECT = "aspect";
// }


// Path: src/main/java/com/jipasoft/config/AspectConfig.java
import com.jipasoft.task.AsyncMailSender;
import com.jipasoft.task.ExceptionAspect;
import com.jipasoft.task.ExceptionInterceptor;
import com.jipasoft.util.Profiles;
import java.util.Map;
import java.util.Properties;
import javax.inject.Inject;
import org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator;
import org.springframework.boot.autoconfigure.mail.MailProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/*
* Copyright 2016, Julius Krah
* by the @authors tag. See the LICENCE in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jipasoft.config;





/**
 * Configures asynchronous mailing When an exception is encountered in the
 * application, it will send an email to the developer.<br />
 * It may also send the <i>Stacktrace</i> of the error depending on the
 * configured property of the application.<br />
 * <p>
 * 
 * The application's email feature can be enabled when the {@code aspect}
 * profile is active.
 * </p>
 * 
 * @author Julius Krah
 *
 */
@EnableAsync
@Profile(Profiles.ASPECT)
@Configuration
@ComponentScan(basePackageClasses = ExceptionAspect.class)