package org.fiware.apps.marketplace.model;

import static javax.persistence.GenerationType.IDENTITY;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlID;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

import org.fiware.apps.marketplace.utils.xmladapters.HiddenFieldsXMLAdapter;
import org.fiware.apps.marketplace.utils.xmladapters.PasswordXMLAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

@Entity
@XmlRootElement(name = "user")
public class Localuser {
	
	private Integer id;
	private String username;
	private String password;
	private String email;
	private Date registrationDate;
	private String company;
		
	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "LOCALUSER_ID", unique = true, nullable = false)
	@XmlTransient
	public Integer getId() {
		return id;
	}
	
	public void setId(Integer  id) {
		this.id = id;
	}
	
	@XmlID
	@XmlAttribute 
	@Column(name = "LOCALUSER_USERNAME", unique = true, nullable = false)
	public String getUsername() {
		return username;
	}
	
	public void setUsername(String username) {
		this.username = username;
	}
	
	@XmlElement
	// Avoid returning the password in the API
	// Encrypt the password received through the API
	@XmlJavaTypeAdapter(PasswordXMLAdapter.class)
	@Column(name = "LOCALUSER_PASSWORD", nullable = false)
	public String getPassword() {
		return password;
	}
	
	public void setPassword(String password) {
		// The password is encoded using the user name as salt
		this.password = password;
	}
	
	@XmlElement
	// Avoid returning the mail in the API
	@XmlJavaTypeAdapter(HiddenFieldsXMLAdapter.class)
	@Column(name = "LOCALUSER_EMAIL", unique = true, nullable = false)
	public String getEmail() {
		return email;
	}
	
	public void setEmail(String email) {
		this.email = email;
	}
	
	@XmlElement
	@Column(name = "LOCALUSER_REGISTRATION_DATE", nullable = false)
	public Date getRegistrationDate() {
		return registrationDate;
	}
	
	public void setRegistrationDate(Date registrationDate) {
		this.registrationDate = registrationDate;
	}
	
	@XmlElement
	@Column(name = "LOCALUSER_COMPANY")
	public String getCompany() {
		return company;
	}
	
	public void setCompany(String company) {
		this.company = company;
	}
	
	@Override
	public int hashCode() {
		return this.id == null ? 0 : this.id;
	}
	
	@Override
	public boolean equals(Object obj) {
		Localuser other = (Localuser) obj;
		return other.id == this.id;
	}

}

@@ -699,150 +699,8 @@
 ter;
-%0Aimport org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;%0Aimport org.springframework.security.crypto.password.PasswordEncoder;
 %0A%0A@E

Remove unneeded imports