// Path: src/main/java/com/jipasoft/domain/User.java
// @Data
// @Entity
// @Document(collection = "account")
// @Table(name = "account")
// @ToString(exclude = { "password", "authorities" })
// @EqualsAndHashCode(callSuper = true)
// public class User extends AbstractAuditEntity implements Serializable {
// 
// 	private static final long serialVersionUID = 1L;
// 
// 	@Id
// 	@org.springframework.data.annotation.Id
// 	@GeneratedValue(generator = "uuid2")
// 	@GenericGenerator(name = "uuid2", strategy = "uuid2")
// 	private String id;
// 
// 	@NotNull
// 	@Pattern(regexp = "^[a-z0-9]*$|(anonymousUser)")
// 	@Size(min = 1, max = 100)
// 	@Column(unique = true)
// 	private String login;
// 
// 	@NotNull
// 	@Size(min = 60, max = 60)
// 	@Column(name = "password_hash")
// 	@JsonIgnore
// 	private String password;
// 
// 	@Size(max = 50)
// 	@Field("first_name")
// 	private String firstName;
// 
// 	@Size(max = 50)
// 	@Field("last_name")
// 	private String lastName;
// 
// 	@NotNull
// 	@Size(min = 1, max = 100)
// 	@Column(unique = true)
// 	private String email;
// 
// 	@NotNull
// 	private boolean activated = false;
// 
// 	@Size(max = 20)
// 	@Field("activation_key")
// 	@JsonIgnore
// 	private String activationKey;
// 
// 	@Size(max = 20)
// 	@Field("reset_key")
// 	@JsonIgnore
// 	private String resetKey;
// 
// 	@Field("reset_date")
// 	private ZonedDateTime resetDate = null;
// 
// 	@ManyToMany
// 	//@formatter:off
// 	@JoinTable(name = "user_role", inverseJoinColumns = {
// 			@JoinColumn(name = "role_name")
// 		}, joinColumns = {
// 			@JoinColumn(name = "account_id")
// 		}
// 	)
// 	//@formatter:on
// 	private Set<Authority> authorities;
// }
// 
// Path: src/main/java/com/jipasoft/repository/UserRepository.java
// @NoRepositoryBean
// public interface UserRepository extends BaseRepository<User, String> {
// 
// 	/**
// 	 * Retrieves a {@link User} entity from the underlying datastore by its
// 	 * ResetKey
// 	 * 
// 	 * @param resetKey
// 	 *            the resetKey
// 	 * @return a User entity
// 	 * @see User#getResetKey()
// 	 */
// 	public Optional<User> findOneByResetKey(String resetKey);
// 
// 	/**
// 	 * Retrieves a {@link User} entity from the underlying datastore by its
// 	 * Email
// 	 * 
// 	 * @param email
// 	 *            the User's email
// 	 * @return a User entity
// 	 * @see User#getEmail()
// 	 */
// 	public Optional<User> findOneByEmail(String email);
// 
// 	/**
// 	 * Retrieves a {@link User} entity from the underlying datastore by its
// 	 * login
// 	 * 
// 	 * @param login
// 	 *            the username
// 	 * @return a User entity
// 	 * @see User#getLogin()
// 	 */
// 	public Optional<User> findOneByLogin(String login);
// 
// }


import java.util.Optional;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import org.springframework.stereotype.Repository;
import com.jipasoft.domain.User;
import com.jipasoft.repository.UserRepository;
/*
* 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.repository.postgres;





/**
 * An implementation of {@link UserRepository} which uses {@link EntityManager}.
 * This is used for the {@code postgres} profile
 * 
 * @author Julius Krah
 *
 */
@Repository
public class UserRepositoryImpl extends BaseRepositoryImpl<User, String> implements UserRepository {

	public UserRepositoryImpl() {
		super(User.class);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public Optional<User> findOneByResetKey(String resetKey) {
		Query query = this.em.createQuery("SELECT u FROM User u WHERE u.resetKey LIKE :resetKey");
		query.setParameter("resetKey", resetKey);
// Path: src/main/java/com/jipasoft/domain/User.java
// @Data
// @Entity
// @Document(collection = "account")
// @Table(name = "account")
// @ToString(exclude = { "password", "authorities" })
// @EqualsAndHashCode(callSuper = true)
// public class User extends AbstractAuditEntity implements Serializable {
// 
// 	private static final long serialVersionUID = 1L;
// 
// 	@Id
// 	@org.springframework.data.annotation.Id
// 	@GeneratedValue(generator = "uuid2")
// 	@GenericGenerator(name = "uuid2", strategy = "uuid2")
// 	private String id;
// 
// 	@NotNull
// 	@Pattern(regexp = "^[a-z0-9]*$|(anonymousUser)")
// 	@Size(min = 1, max = 100)
// 	@Column(unique = true)
// 	private String login;
// 
// 	@NotNull
// 	@Size(min = 60, max = 60)
// 	@Column(name = "password_hash")
// 	@JsonIgnore
// 	private String password;
// 
// 	@Size(max = 50)
// 	@Field("first_name")
// 	private String firstName;
// 
// 	@Size(max = 50)
// 	@Field("last_name")
// 	private String lastName;
// 
// 	@NotNull
// 	@Size(min = 1, max = 100)
// 	@Column(unique = true)
// 	private String email;
// 
// 	@NotNull
// 	private boolean activated = false;
// 
// 	@Size(max = 20)
// 	@Field("activation_key")
// 	@JsonIgnore
// 	private String activationKey;
// 
// 	@Size(max = 20)
// 	@Field("reset_key")
// 	@JsonIgnore
// 	private String resetKey;
// 
// 	@Field("reset_date")
// 	private ZonedDateTime resetDate = null;
// 
// 	@ManyToMany
// 	//@formatter:off
// 	@JoinTable(name = "user_role", inverseJoinColumns = {
// 			@JoinColumn(name = "role_name")
// 		}, joinColumns = {
// 			@JoinColumn(name = "account_id")
// 		}
// 	)
// 	//@formatter:on
// 	private Set<Authority> authorities;
// }
// 
// Path: src/main/java/com/jipasoft/repository/UserRepository.java
// @NoRepositoryBean
// public interface UserRepository extends BaseRepository<User, String> {
// 
// 	/**
// 	 * Retrieves a {@link User} entity from the underlying datastore by its
// 	 * ResetKey
// 	 * 
// 	 * @param resetKey
// 	 *            the resetKey
// 	 * @return a User entity
// 	 * @see User#getResetKey()
// 	 */
// 	public Optional<User> findOneByResetKey(String resetKey);
// 
// 	/**
// 	 * Retrieves a {@link User} entity from the underlying datastore by its
// 	 * Email
// 	 * 
// 	 * @param email
// 	 *            the User's email
// 	 * @return a User entity
// 	 * @see User#getEmail()
// 	 */
// 	public Optional<User> findOneByEmail(String email);
// 
// 	/**
// 	 * Retrieves a {@link User} entity from the underlying datastore by its
// 	 * login
// 	 * 
// 	 * @param login
// 	 *            the username
// 	 * @return a User entity
// 	 * @see User#getLogin()
// 	 */
// 	public Optional<User> findOneByLogin(String login);
// 
// }


// Path: src/main/java/com/jipasoft/repository/postgres/UserRepositoryImpl.java
import java.util.Optional;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import org.springframework.stereotype.Repository;
import com.jipasoft.domain.User;
import com.jipasoft.repository.UserRepository;

/*
* 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.repository.postgres;





/**
 * An implementation of {@link UserRepository} which uses {@link EntityManager}.
 * This is used for the {@code postgres} profile
 * 
 * @author Julius Krah
 *
 */
@Repository
public class UserRepositoryImpl extends BaseRepositoryImpl<User, String> implements UserRepository {

	public UserRepositoryImpl() {
		super(User.class);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public Optional<User> findOneByResetKey(String resetKey) {
		Query query = this.em.createQuery("SELECT u FROM User u WHERE u.resetKey LIKE :resetKey");
		query.setParameter("resetKey", resetKey);
		return Optional.ofNullable((User) query.getSingleResult());