// Path: core/src/main/java/org/meruvian/yama/core/user/User.java
// @Entity
// @Table(name = "yama_backend_user")
// public class User extends DefaultPersistence {
// 	private String username;
// 	private String password;
// 	private String email;
// 	private Name name = new Name();
// 	private Address address = new Address();
// 	private FileInfo fileInfo;
// 	private List<UserRole> roles = new ArrayList<UserRole>();
// 	
// 	@NotNull
// 	@Size(min = 6)
// 	@Column(name = "username", unique = true, nullable = false)
// 	public String getUsername() {
// 		return username;
// 	}
// 
// 	public void setUsername(String username) {
// 		this.username = username;
// 	}
// 
// 	@Column(name = "password", nullable = false)
// 	public String getPassword() {
// 		return password;
// 	}
// 
// 	public void setPassword(String password) {
// 		this.password = password;
// 	}
// 
// 	@NotNull
// 	@Column(name = "email", unique = true, nullable = false)
// 	public String getEmail() {
// 		return email;
// 	}
// 
// 	public void setEmail(String email) {
// 		this.email = email;
// 	}
// 
// 	@Embedded
// 	public Name getName() {
// 		return name;
// 	}
// 
// 	public void setName(Name name) {
// 		this.name = name;
// 	}
// 	
// 	@Embedded
// 	public Address getAddress() {
// 		return address;
// 	}
// 
// 	public void setAddress(Address address) {
// 		this.address = address;
// 	}
// 
// 	@ManyToOne
// 	@JoinColumn(name = "file_info_id")
// 	public FileInfo getFileInfo() {
// 		return fileInfo;
// 	}
// 	
// 	public void setFileInfo(FileInfo fileInfo) {
// 		this.fileInfo = fileInfo;
// 	}
// 
// 	@JsonIgnore
// 	@OneToMany(mappedBy = "user", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)
// 	public List<UserRole> getRoles() {
// 		return roles;
// 	}
// 
// 	public void setRoles(List<UserRole> roles) {
// 		this.roles = roles;
// 	}
// }
// 
// Path: webapi/src/main/java/org/meruvian/yama/webapi/service/commons/EmailService.java
// @Service
// public class EmailService {
// 	private final Logger log = LoggerFactory.getLogger(EmailService.class);
// 	
// 	@Inject
// 	private HtmlEmail htmlEmail;
// 	
// 	@Inject
// 	private Configuration configuration;
// 
// 	@Async
// 	public void sendEmail(String to, String subject, String template, Object templateModel) {
// 		log.debug("Sending email to {}", to);
// 		
// 		try {
// 			StringWriter emailContent = new StringWriter();
// 			Template emailTemplate = configuration.getTemplate(template);
// 			emailTemplate.process(templateModel, emailContent);
// 			
// 			htmlEmail.setSubject(subject);
// 			htmlEmail.addTo(to);
// 			htmlEmail.setHtmlMsg(emailContent.toString());
// 			htmlEmail.send();
// 		} catch (IOException e) {
// 			log.error("Error occured while creating email template", e);
// 		} catch (TemplateException e) {
// 			log.error("Error occured while creating email template", e);
// 		} catch (EmailException e) {
// 			log.warn("Email could not be sent to {}", to, e);
// 		}
// 	}
// }


import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
import javax.inject.Inject;
import org.hibernate.event.service.spi.EventListenerRegistry;
import org.hibernate.event.spi.EventType;
import org.hibernate.event.spi.PostInsertEvent;
import org.hibernate.event.spi.PostInsertEventListener;
import org.hibernate.persister.entity.EntityPersister;
import org.meruvian.yama.core.user.User;
import org.meruvian.yama.webapi.service.commons.EmailService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
/**
 * Copyright 2014 Meruvian
 *
 * 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 org.meruvian.yama.webapi.config.persistence;




/**
 * @author Dian Aditya
 *
 */
@Component
public class UserRegisteredListener implements PostInsertEventListener {
	private final Logger log = LoggerFactory.getLogger(UserRegisteredListener.class);
	
	@Inject
	public UserRegisteredListener(EventListenerRegistry registry) {
		registry.getEventListenerGroup(EventType.POST_INSERT).appendListener(this);
	}
	
	@Inject
	private EmailService emailService;
	
	@Override
	public void onPostInsert(PostInsertEvent event) {
// Path: core/src/main/java/org/meruvian/yama/core/user/User.java
// @Entity
// @Table(name = "yama_backend_user")
// public class User extends DefaultPersistence {
// 	private String username;
// 	private String password;
// 	private String email;
// 	private Name name = new Name();
// 	private Address address = new Address();
// 	private FileInfo fileInfo;
// 	private List<UserRole> roles = new ArrayList<UserRole>();
// 	
// 	@NotNull
// 	@Size(min = 6)
// 	@Column(name = "username", unique = true, nullable = false)
// 	public String getUsername() {
// 		return username;
// 	}
// 
// 	public void setUsername(String username) {
// 		this.username = username;
// 	}
// 
// 	@Column(name = "password", nullable = false)
// 	public String getPassword() {
// 		return password;
// 	}
// 
// 	public void setPassword(String password) {
// 		this.password = password;
// 	}
// 
// 	@NotNull
// 	@Column(name = "email", unique = true, nullable = false)
// 	public String getEmail() {
// 		return email;
// 	}
// 
// 	public void setEmail(String email) {
// 		this.email = email;
// 	}
// 
// 	@Embedded
// 	public Name getName() {
// 		return name;
// 	}
// 
// 	public void setName(Name name) {
// 		this.name = name;
// 	}
// 	
// 	@Embedded
// 	public Address getAddress() {
// 		return address;
// 	}
// 
// 	public void setAddress(Address address) {
// 		this.address = address;
// 	}
// 
// 	@ManyToOne
// 	@JoinColumn(name = "file_info_id")
// 	public FileInfo getFileInfo() {
// 		return fileInfo;
// 	}
// 	
// 	public void setFileInfo(FileInfo fileInfo) {
// 		this.fileInfo = fileInfo;
// 	}
// 
// 	@JsonIgnore
// 	@OneToMany(mappedBy = "user", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)
// 	public List<UserRole> getRoles() {
// 		return roles;
// 	}
// 
// 	public void setRoles(List<UserRole> roles) {
// 		this.roles = roles;
// 	}
// }
// 
// Path: webapi/src/main/java/org/meruvian/yama/webapi/service/commons/EmailService.java
// @Service
// public class EmailService {
// 	private final Logger log = LoggerFactory.getLogger(EmailService.class);
// 	
// 	@Inject
// 	private HtmlEmail htmlEmail;
// 	
// 	@Inject
// 	private Configuration configuration;
// 
// 	@Async
// 	public void sendEmail(String to, String subject, String template, Object templateModel) {
// 		log.debug("Sending email to {}", to);
// 		
// 		try {
// 			StringWriter emailContent = new StringWriter();
// 			Template emailTemplate = configuration.getTemplate(template);
// 			emailTemplate.process(templateModel, emailContent);
// 			
// 			htmlEmail.setSubject(subject);
// 			htmlEmail.addTo(to);
// 			htmlEmail.setHtmlMsg(emailContent.toString());
// 			htmlEmail.send();
// 		} catch (IOException e) {
// 			log.error("Error occured while creating email template", e);
// 		} catch (TemplateException e) {
// 			log.error("Error occured while creating email template", e);
// 		} catch (EmailException e) {
// 			log.warn("Email could not be sent to {}", to, e);
// 		}
// 	}
// }


// Path: webapi/src/main/java/org/meruvian/yama/webapi/config/persistence/UserRegisteredListener.java
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
import javax.inject.Inject;
import org.hibernate.event.service.spi.EventListenerRegistry;
import org.hibernate.event.spi.EventType;
import org.hibernate.event.spi.PostInsertEvent;
import org.hibernate.event.spi.PostInsertEventListener;
import org.hibernate.persister.entity.EntityPersister;
import org.meruvian.yama.core.user.User;
import org.meruvian.yama.webapi.service.commons.EmailService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;

/**
 * Copyright 2014 Meruvian
 *
 * 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 org.meruvian.yama.webapi.config.persistence;




/**
 * @author Dian Aditya
 *
 */
@Component
public class UserRegisteredListener implements PostInsertEventListener {
	private final Logger log = LoggerFactory.getLogger(UserRegisteredListener.class);
	
	@Inject
	public UserRegisteredListener(EventListenerRegistry registry) {
		registry.getEventListenerGroup(EventType.POST_INSERT).appendListener(this);
	}
	
	@Inject
	private EmailService emailService;
	
	@Override
	public void onPostInsert(PostInsertEvent event) {
		if (event.getEntity() instanceof User) {