package net.davidvoid.thor.lightning.data.access;

import net.davidvoid.thor.lightning.entity.Entity;
import net.davidvoid.thor.lightning.entity.User;

import org.springframework.stereotype.Component;

import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;

/**
 * Created by david on 3/21/16. {_id: XXXX, id: long, name: string, password:
 * String} index 1: id, unique index 2: name, unique
 */
@Component
public class UserStore extends AbstractStore {

    private static final String COLLECTION_NAME = "user";

    public User getByName(String name) {
        BasicDBObject query = new BasicDBObject("name", name);
        return (User) getOne(query);
    }

    public User getById(long id) {
        BasicDBObject query = new BasicDBObject("id", id);
        return (User) getOne(query);
    }

    @Override
    protected DBObject toDBObject(Entity entity) {
        User user = (User) entity;

        BasicDBObject object = new BasicDBObject("name", user.getName());
        if (user.has_valid_id())
            object.put("id", user.getId());
        object.put("password", user.getPassword());

        return object;
    }

    @Override
    protected Entity toEntity(DBObject object) {
        User user = new User();
        user.setId((long) object.get("id"));
        user.setName((String) object.get("name"));
        user.setPassword((String) object.get("password"));

        return user;
    }

    @Override
    protected DBObject getModifyQuery(Entity entity) {
        User user = (User) entity;
        return new BasicDBObject("id", user.getId());
    }

    @Override
    protected String getCollectionName() {
        return COLLECTION_NAME;
    }
}

@@ -193,16 +193,65 @@
 mponent;
+%0Aimport static org.springframework.util.Assert.*;
 %0A%0Aimport
@@ -602,24 +602,81 @@
 ing name) %7B%0A
+        notNull(name);%0A        hasLength(name);%0A        %0A
         Basi
@@ -965,32 +965,72 @@
 ntity entity) %7B%0A
+        assert entity != null;%0A        %0A
         User use
@@ -1048,17 +1048,16 @@
 entity;%0A
-%0A
         
@@ -1341,24 +1341,64 @@
 t object) %7B%0A
+        assert object != null;%0A        %0A
         User
@@ -1607,32 +1607,32 @@
 %0A%0A    @Override%0A
-
     protected DB
@@ -1662,32 +1662,72 @@
 ntity entity) %7B%0A
+        assert entity != null;%0A        %0A
         User use

add needed assertions