// Path: src/main/java/uk/co/caprica/bootlace/data/mongo/account/AccountRepository.java
// public interface AccountRepository extends MongoRepository<Account, String> {
// 
//     /**
//      * Find an account for a given username.
//      *
//      * @param username username to search for
//      * @return account; or <code>null</code> if no account found for the give username
//      */
//     Account findByUsername(String username);
// 
// }
// 
// Path: src/main/java/uk/co/caprica/bootlace/domain/account/Account.java
// @Document
// public class Account extends AbstractEntity {
// 
//     /**
//      * Username.
//      */
//     @NotNull
//     private String username;
// 
//     /**
//      * Encrypted password.
//      *
//      * Using {@link JsonIgnore} prevents the password being returned by a web-service.
//      */
//     @JsonIgnore
//     @NotNull
//     private String password;
// 
//     /**
//      * List of role authorisations.
//      */
//     private List<String> roles;
// 
//     public Account() {
//     }
// 
//     public String getUsername() {
//         return username;
//     }
// 
//     public void setUsername(String username) {
//         this.username = username;
//     }
// 
//     public String getPassword() {
//         return password;
//     }
// 
//     public void setPassword(String password) {
//         this.password = password;
//     }
// 
//     public List<String> getRoles() {
//         return roles;
//     }
// 
//     public void setRoles(List<String> roles) {
//         this.roles = roles;
//     }
// 
//     @Override
//     public String toString() {
//         return toStringHelper()
//             .add("username", username)
//             .add("roles", roles)
//             .toString();
//     }
// 
// }


import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;
import uk.co.caprica.bootlace.data.mongo.account.AccountRepository;
import uk.co.caprica.bootlace.domain.account.Account;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.index.TextIndexDefinition.TextIndexDefinitionBuilder;
     */
    private void createDatabase() {
        logger.debug("createDatabase()");
        try {
            mongoOperations.createCollection("account");
            mongoOperations.indexOps("account")
                .ensureIndex(new TextIndexDefinitionBuilder()
                    .named("username")
                    .onField("username")
                    .build());
        }
        catch (Exception e) {
            logger.debug("Exception creating database, assuming database already exists");
            // This is most likely because the collection already exists, so ignore the error and
            // carry on
        }
    }

    /**
     * Populate the database with seed data, in particular some demo accounts are created so that
     * application logins and role-based authorisations will work.
     */
    private void seedDatabase() {
        logger.debug("seedDatabase()");
        List<String> adminRoles = new ArrayList<>();
        adminRoles.add("ROLE_ADMIN");
        adminRoles.add("ROLE_USER");
        List<String> userRoles = new ArrayList<>();
        userRoles.add("ROLE_USER");
        if (accountRepository.findByUsername("mark") == null) {
// Path: src/main/java/uk/co/caprica/bootlace/data/mongo/account/AccountRepository.java
// public interface AccountRepository extends MongoRepository<Account, String> {
// 
//     /**
//      * Find an account for a given username.
//      *
//      * @param username username to search for
//      * @return account; or <code>null</code> if no account found for the give username
//      */
//     Account findByUsername(String username);
// 
// }
// 
// Path: src/main/java/uk/co/caprica/bootlace/domain/account/Account.java
// @Document
// public class Account extends AbstractEntity {
// 
//     /**
//      * Username.
//      */
//     @NotNull
//     private String username;
// 
//     /**
//      * Encrypted password.
//      *
//      * Using {@link JsonIgnore} prevents the password being returned by a web-service.
//      */
//     @JsonIgnore
//     @NotNull
//     private String password;
// 
//     /**
//      * List of role authorisations.
//      */
//     private List<String> roles;
// 
//     public Account() {
//     }
// 
//     public String getUsername() {
//         return username;
//     }
// 
//     public void setUsername(String username) {
//         this.username = username;
//     }
// 
//     public String getPassword() {
//         return password;
//     }
// 
//     public void setPassword(String password) {
//         this.password = password;
//     }
// 
//     public List<String> getRoles() {
//         return roles;
//     }
// 
//     public void setRoles(List<String> roles) {
//         this.roles = roles;
//     }
// 
//     @Override
//     public String toString() {
//         return toStringHelper()
//             .add("username", username)
//             .add("roles", roles)
//             .toString();
//     }
// 
// }


// Path: src/main/java/uk/co/caprica/bootlace/startup/ApplicationStartup.java
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;
import uk.co.caprica.bootlace.data.mongo.account.AccountRepository;
import uk.co.caprica.bootlace.domain.account.Account;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.index.TextIndexDefinition.TextIndexDefinitionBuilder;

     */
    private void createDatabase() {
        logger.debug("createDatabase()");
        try {
            mongoOperations.createCollection("account");
            mongoOperations.indexOps("account")
                .ensureIndex(new TextIndexDefinitionBuilder()
                    .named("username")
                    .onField("username")
                    .build());
        }
        catch (Exception e) {
            logger.debug("Exception creating database, assuming database already exists");
            // This is most likely because the collection already exists, so ignore the error and
            // carry on
        }
    }

    /**
     * Populate the database with seed data, in particular some demo accounts are created so that
     * application logins and role-based authorisations will work.
     */
    private void seedDatabase() {
        logger.debug("seedDatabase()");
        List<String> adminRoles = new ArrayList<>();
        adminRoles.add("ROLE_ADMIN");
        adminRoles.add("ROLE_USER");
        List<String> userRoles = new ArrayList<>();
        userRoles.add("ROLE_USER");
        if (accountRepository.findByUsername("mark") == null) {
            Account markAdminAccount = new Account();