// Path: src/main/java/org/swarmcom/jsynapse/dao/UserRepository.java
// public interface UserRepository extends MongoRepository<User, String> {
//     User findOneByUserId(String userId);
// }
// 
// Path: src/main/java/org/swarmcom/jsynapse/domain/AccessToken.java
// public class AccessToken {
//     @Id
//     String id;
// 
//     String userId;
// 
//     String token;
// 
//     Date lastUsed;
// 
//     public AccessToken(@NotNull String userId, @NotNull String token, @NotNull Date lastUsed) {
//         this.userId = userId;
//         this.token = token;
//         this.lastUsed = lastUsed;
//     }
// 
//     public String getId() {
//         return id;
//     }
// 
//     public void setId(String id) {
//         this.id = id;
//     }
// 
//     public String getUserId() {
//         return userId;
//     }
// 
//     public void setUserId(String userId) {
//         this.userId = userId;
//     }
// 
//     public String getToken() {
//         return token;
//     }
// 
//     public void setToken(String token) {
//         this.token = token;
//     }
// 
//     public Date getLastUsed() {
//         return lastUsed;
//     }
// 
//     public void setLastUsed(Date lastUsed) {
//         this.lastUsed = lastUsed;
//     }
// }
// 
// Path: src/main/java/org/swarmcom/jsynapse/domain/User.java
// public class User {
//     @Id
//     String id;
// 
//     String userId;
// 
//     @JsonProperty("password")
//     String hashedPassword;
// 
//     @JsonView(AvatarUrlSummary.class)
//     @JsonProperty("avatar_url")
//     String avatarUrl;
// 
//     @JsonView(DisplayNameSummary.class)
//     @JsonProperty("displayname")
//     String displayName;
// 
//     public User() {
//     }
// 
//     public User(String userId, String hashedPassword) {
//         this.userId = userId;
//         this.hashedPassword = hashedPassword;
//     }
// 
//     public String getUserId() {
//         return userId;
//     }
// 
//     public void setUserId(String userId) {
//         this.userId = userId;
//     }
// 
//     public String getHashedPassword() {
//         return hashedPassword;
//     }
// 
//     public void setHashedPassword(String password) {
//         this.hashedPassword = password;
//     }
// 
//     public String getAvatarUrl() {
//         return avatarUrl;
//     }
// 
//     public void setAvatarUrl(String avatarUrl) {
//         this.avatarUrl = avatarUrl;
//     }
// 
//     public String getDisplayName() {
//         return displayName;
//     }
// 
//     public void setDisplayName(String displayName) {
//         this.displayName = displayName;
//     }
// 
//     public interface DisplayNameSummary {}
// 
//     public interface AvatarUrlSummary {}
// }
// 
// Path: src/main/java/org/swarmcom/jsynapse/service/accesstoken/AccessTokenService.java
// public interface AccessTokenService {
//     public boolean isTokenAssigned(String userId, String token);
// 
//     public AccessToken createOrUpdateToken(AccessToken accessToken);
// }
// 
// Path: src/main/java/org/swarmcom/jsynapse/service/exception/EntityAlreadyExistsException.java
// public class EntityAlreadyExistsException extends RuntimeException {
//     public EntityAlreadyExistsException(final String message) {
//         super(message);
//     }
// }
// 
// Path: src/main/java/org/swarmcom/jsynapse/service/exception/EntityNotFoundException.java
// public class EntityNotFoundException extends RuntimeException {
//     public EntityNotFoundException(final String message) {
//         super(message);
//     }
// }
// 
// Path: src/main/java/org/swarmcom/jsynapse/service/exception/InvalidRequestException.java
// public class InvalidRequestException extends RuntimeException {
//     public InvalidRequestException(final String message) {
//         super(message);
//     }
// }
// 
// Path: src/main/java/org/swarmcom/jsynapse/service/exception/TokenNotFoundException.java
// public class TokenNotFoundException extends RuntimeException {
//     public TokenNotFoundException(String message) {
//         super(message);
//     }
// }


import java.util.Date;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import org.swarmcom.jsynapse.dao.UserRepository;
import org.swarmcom.jsynapse.domain.AccessToken;
import org.swarmcom.jsynapse.domain.User;
import org.swarmcom.jsynapse.service.accesstoken.AccessTokenService;
import org.swarmcom.jsynapse.service.exception.EntityAlreadyExistsException;
import org.swarmcom.jsynapse.service.exception.EntityNotFoundException;
import org.swarmcom.jsynapse.service.exception.InvalidRequestException;
import org.swarmcom.jsynapse.service.exception.TokenNotFoundException;
import javax.inject.Inject;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
/*
 * (C) Copyright 2015 eZuce Inc.
 *
 * 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.swarmcom.jsynapse.service.user;




@Service
@Validated
public class UserServiceImpl implements UserService {
    private UserRepository repository;
    private AccessTokenService accessTokenService;

    @Inject
    public UserServiceImpl(UserRepository repository, AccessTokenService accessTokenService) {
        this.repository = repository;
        this.accessTokenService = accessTokenService;
    }

    @Override
    public User createUser(@NotNull @Valid final User user) {
        User existingUser = repository.findOneByUserId(user.getUserId());
        if (existingUser != null) {
            throw new EntityAlreadyExistsException("User already created");
        }
        User createdUser = repository.save(user);
        return createdUser;
    }

    @Override
// Path: src/main/java/org/swarmcom/jsynapse/dao/UserRepository.java
// public interface UserRepository extends MongoRepository<User, String> {
//     User findOneByUserId(String userId);
// }
// 
// Path: src/main/java/org/swarmcom/jsynapse/domain/AccessToken.java
// public class AccessToken {
//     @Id
//     String id;
// 
//     String userId;
// 
//     String token;
// 
//     Date lastUsed;
// 
//     public AccessToken(@NotNull String userId, @NotNull String token, @NotNull Date lastUsed) {
//         this.userId = userId;
//         this.token = token;
//         this.lastUsed = lastUsed;
//     }
// 
//     public String getId() {
//         return id;
//     }
// 
//     public void setId(String id) {
//         this.id = id;
//     }
// 
//     public String getUserId() {
//         return userId;
//     }
// 
//     public void setUserId(String userId) {
//         this.userId = userId;
//     }
// 
//     public String getToken() {
//         return token;
//     }
// 
//     public void setToken(String token) {
//         this.token = token;
//     }
// 
//     public Date getLastUsed() {
//         return lastUsed;
//     }
// 
//     public void setLastUsed(Date lastUsed) {
//         this.lastUsed = lastUsed;
//     }
// }
// 
// Path: src/main/java/org/swarmcom/jsynapse/domain/User.java
// public class User {
//     @Id
//     String id;
// 
//     String userId;
// 
//     @JsonProperty("password")
//     String hashedPassword;
// 
//     @JsonView(AvatarUrlSummary.class)
//     @JsonProperty("avatar_url")
//     String avatarUrl;
// 
//     @JsonView(DisplayNameSummary.class)
//     @JsonProperty("displayname")
//     String displayName;
// 
//     public User() {
//     }
// 
//     public User(String userId, String hashedPassword) {
//         this.userId = userId;
//         this.hashedPassword = hashedPassword;
//     }
// 
//     public String getUserId() {
//         return userId;
//     }
// 
//     public void setUserId(String userId) {
//         this.userId = userId;
//     }
// 
//     public String getHashedPassword() {
//         return hashedPassword;
//     }
// 
//     public void setHashedPassword(String password) {
//         this.hashedPassword = password;
//     }
// 
//     public String getAvatarUrl() {
//         return avatarUrl;
//     }
// 
//     public void setAvatarUrl(String avatarUrl) {
//         this.avatarUrl = avatarUrl;
//     }
// 
//     public String getDisplayName() {
//         return displayName;
//     }
// 
//     public void setDisplayName(String displayName) {
//         this.displayName = displayName;
//     }
// 
//     public interface DisplayNameSummary {}
// 
//     public interface AvatarUrlSummary {}
// }
// 
// Path: src/main/java/org/swarmcom/jsynapse/service/accesstoken/AccessTokenService.java
// public interface AccessTokenService {
//     public boolean isTokenAssigned(String userId, String token);
// 
//     public AccessToken createOrUpdateToken(AccessToken accessToken);
// }
// 
// Path: src/main/java/org/swarmcom/jsynapse/service/exception/EntityAlreadyExistsException.java
// public class EntityAlreadyExistsException extends RuntimeException {
//     public EntityAlreadyExistsException(final String message) {
//         super(message);
//     }
// }
// 
// Path: src/main/java/org/swarmcom/jsynapse/service/exception/EntityNotFoundException.java
// public class EntityNotFoundException extends RuntimeException {
//     public EntityNotFoundException(final String message) {
//         super(message);
//     }
// }
// 
// Path: src/main/java/org/swarmcom/jsynapse/service/exception/InvalidRequestException.java
// public class InvalidRequestException extends RuntimeException {
//     public InvalidRequestException(final String message) {
//         super(message);
//     }
// }
// 
// Path: src/main/java/org/swarmcom/jsynapse/service/exception/TokenNotFoundException.java
// public class TokenNotFoundException extends RuntimeException {
//     public TokenNotFoundException(String message) {
//         super(message);
//     }
// }


// Path: src/main/java/org/swarmcom/jsynapse/service/user/UserServiceImpl.java
import java.util.Date;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import org.swarmcom.jsynapse.dao.UserRepository;
import org.swarmcom.jsynapse.domain.AccessToken;
import org.swarmcom.jsynapse.domain.User;
import org.swarmcom.jsynapse.service.accesstoken.AccessTokenService;
import org.swarmcom.jsynapse.service.exception.EntityAlreadyExistsException;
import org.swarmcom.jsynapse.service.exception.EntityNotFoundException;
import org.swarmcom.jsynapse.service.exception.InvalidRequestException;
import org.swarmcom.jsynapse.service.exception.TokenNotFoundException;
import javax.inject.Inject;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/*
 * (C) Copyright 2015 eZuce Inc.
 *
 * 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.swarmcom.jsynapse.service.user;




@Service
@Validated
public class UserServiceImpl implements UserService {
    private UserRepository repository;
    private AccessTokenService accessTokenService;

    @Inject
    public UserServiceImpl(UserRepository repository, AccessTokenService accessTokenService) {
        this.repository = repository;
        this.accessTokenService = accessTokenService;
    }

    @Override
    public User createUser(@NotNull @Valid final User user) {
        User existingUser = repository.findOneByUserId(user.getUserId());
        if (existingUser != null) {
            throw new EntityAlreadyExistsException("User already created");
        }
        User createdUser = repository.save(user);
        return createdUser;
    }

    @Override
    public User findUserById(String userId) {