package ca.corefacility.bioinformatics.irida.repositories.memory;

import ca.corefacility.bioinformatics.irida.exceptions.user.UserNotFoundException;
import ca.corefacility.bioinformatics.irida.model.roles.impl.Identifier;
import ca.corefacility.bioinformatics.irida.model.User;
import ca.corefacility.bioinformatics.irida.repositories.UserRepository;

/**
 * An in-memory implementation of a user repository, for testing purposes only.
 *
 * @author Franklin Bristow <franklin.bristow@phac-aspc.gc.ca>
 */
public class UserMemoryRepository extends CRUDMemoryRepository<User> implements UserRepository {

    public UserMemoryRepository() {
        super(User.class);
        Identifier id = new Identifier();
        store.put(id, new User(id, "jsadam", "j@me.com", "pass1234", "Jake", "Penner", "787-9998"));
        id = new Identifier();
        store.put(id, new User(id, "hjadam", "h@me.com", "pass5678", "Hammy", "Penner", "787-1234"));
        id = new Identifier();
        store.put(id, new User(id, "njadam", "n@me.com", "1234pass", "Ninja", "Penner", "787-5678"));
        id = new Identifier();
        store.put(id, new User(id, "badam", "n@me.com", "1234pass", "Ninja", "Penner", "787-5678"));
        id = new Identifier();
        store.put(id, new User(id, "cadam", "n@me.com", "1234pass", "Ninja", "Penner", "787-5678"));
        id = new Identifier();
        store.put(id, new User(id, "dadam", "n@me.com", "1234pass", "Ninja", "Penner", "787-5678"));
        id = new Identifier();
        store.put(id, new User(id, "eadam", "n@me.com", "1234pass", "Ninja", "Penner", "787-5678"));
        id = new Identifier();
        store.put(id, new User(id, "fadam", "n@me.com", "1234pass", "Ninja", "Penner", "787-5678"));
        id = new Identifier();
        store.put(id, new User(id, "gadam", "n@me.com", "1234pass", "Ninja", "Penner", "787-5678"));
        id = new Identifier();
        store.put(id, new User(id, "hadam", "n@me.com", "1234pass", "Ninja", "Penner", "787-5678"));
        id = new Identifier();
        store.put(id, new User(id, "iadam", "n@me.com", "1234pass", "Ninja", "Penner", "787-5678"));
        id = new Identifier();
        store.put(id, new User(id, "jadam", "n@me.com", "1234pass", "Ninja", "Penner", "787-5678"));
        id = new Identifier();
        store.put(id, new User(id, "kadam", "n@me.com", "1234pass", "Ninja", "Penner", "787-5678"));
        id = new Identifier();
        store.put(id, new User(id, "ladam", "n@me.com", "1234pass", "Ninja", "Penner", "787-5678"));
        id = new Identifier();
        store.put(id, new User(id, "madam", "n@me.com", "1234pass", "Ninja", "Penner", "787-5678"));
        id = new Identifier();
        store.put(id, new User(id, "nadam", "n@me.com", "1234pass", "Ninja", "Penner", "787-5678"));
        id = new Identifier();
        store.put(id, new User(id, "oadam", "n@me.com", "1234pass", "Ninja", "Penner", "787-5678"));
        id = new Identifier();
        store.put(id, new User(id, "padam", "n@me.com", "1234pass", "Ninja", "Penner", "787-5678"));
        id = new Identifier();
        store.put(id, new User(id, "jlky", "n@me.com", "1234pass", "Ninja", "Penner", "787-5678"));
        id = new Identifier();
        store.put(id, new User(id, "jlouh", "n@me.com", "1234pass", "Ninja", "Penner", "787-5678"));
        id = new Identifier();
        store.put(id, new User(id, "nklfr", "n@me.com", "1234pass", "Ninja", "Penner", "787-5678"));
        id = new Identifier();
        store.put(id, new User(id, "jkgtffjh", "n@me.com", "1234pass", "Ninja", "Penner", "787-5678"));
        id = new Identifier();
        store.put(id, new User(id, "kljkhjlkjlk", "n@me.com", "1234pass", "Ninja", "Penner", "787-5678"));
        id = new Identifier();
        store.put(id, new User(id, "klj;lkkj;l", "n@me.com", "1234pass", "Ninja", "Penner", "787-5678"));
        id = new Identifier();
        store.put(id, new User(id, "jkhkjh", "n@me.com", "1234pass", "Ninja", "Penner", "787-5678"));
        id = new Identifier();
        store.put(id, new User(id, "kljlkj", "n@me.com", "1234pass", "Ninja", "Penner", "787-5678"));
    }

    @Override
    public User getUserByUsername(String username) throws UserNotFoundException {
        User u = null;

        for (User entry : store.values()) {
            if (entry.getUsername().equals(username)) {
                u = entry;
                break;
            }
        }

        if (u == null) {
            throw new UserNotFoundException("No user with username [" + username + "] exists.");
        }

        return u;
    }
}

@@ -143,16 +143,131 @@
 eption;%0A
+import ca.corefacility.bioinformatics.irida.model.Project;%0Aimport ca.corefacility.bioinformatics.irida.model.Role;%0A
 import c
@@ -822,37 +822,32 @@
 ();%0A        
-store.put(id,
+User u =
  new User(id
@@ -911,16 +911,197 @@
 7-9998%22)
+;%0A        Project p = new Project();%0A        p.setIdentifier(new Identifier());%0A        p.setName(%22The super project.%22);%0A        u.addProject(p, new Role());%0A        store.put(id, u
 );%0A     

Add a project to one of the users for testing.