package com.github.cstroe.spendhawk.entity;

import com.github.cstroe.spendhawk.util.HibernateUtil;
import org.hibernate.criterion.Restrictions;

import java.util.Collection;
import java.util.Optional;

/**
 * A user has:
 * <ul>
 *     <li>A unique database id.</li>
 *     <li>A user name.  Used for identification in the system.</li>
 *     <li>Many accounts.</li>
 *     <li>Many expense categories.</li>
 * </ul>
 */
public class User {
    private Long id;
    private String name;
    private Collection<Account> accounts;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Collection<Account> getAccounts() {
        return accounts;
    }

    public void setAccounts(Collection<Account> accounts) {
        this.accounts = accounts;
    }

    public static Optional<User> findById(Long id) {
        return Optional.ofNullable((User) HibernateUtil.getSessionFactory().getCurrentSession()
                .createCriteria(User.class)
                .add(Restrictions.eq("id", id))
                .uniqueResult());
    }

}

@@ -435,16 +435,233 @@
  User %7B%0A
+%0A    public static final String DEFAULT_INCOME_ACCOUNT_NAME = %22Income%22;%0A    public static final String DEFAULT_EXPENSE_ACCOUNT_NAME = %22Expenses%22;%0A    public static final String DEFAULT_ASSET_ACCOUNT_NAME = %22Assets%22;%0A%0A
     priv
@@ -1157,32 +1157,593 @@
 ccounts;%0A    %7D%0A%0A
+    public Optional%3CAccount%3E getAccountByName(String name) %7B%0A        return this.accounts.stream()%0A            .filter(a -%3E a.getName().equals(name))%0A            .findFirst();%0A    %7D%0A%0A    public Optional%3CAccount%3E getDefaultExpenseAccount() %7B%0A        return getAccountByName(DEFAULT_EXPENSE_ACCOUNT_NAME);%0A    %7D%0A%0A    public Optional%3CAccount%3E getDefaultIncomeAccount() %7B%0A        return getAccountByName(DEFAULT_INCOME_ACCOUNT_NAME);%0A    %7D%0A%0A    public Optional%3CAccount%3E getDefaultAssetAccount() %7B%0A        return getAccountByName(DEFAULT_ASSET_ACCOUNT_NAME);%0A    %7D%0A%0A
     public stati

Add the concept of default accounts to the User entity.