package at.fhjoanneum.ippr.gateway.security.usermapping.retrieval.memory;

import java.util.Map;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

import at.fhjoanneum.ippr.gateway.security.persistence.entities.cache.CacheGroup;
import at.fhjoanneum.ippr.gateway.security.persistence.entities.cache.CacheUser;
import at.fhjoanneum.ippr.gateway.security.usermapping.retrieval.UserGroupSystemRetrievalService;

public class UserGroupSystemRetrievalServiceMemoryImpl implements UserGroupSystemRetrievalService {

  private static Map<String, CacheUser> users;

  @Override
  public Map<String, CacheUser> getSystemUsers() {
    if (users == null) {
      createMemoryUsers();
    }
    return users;
  }

  private void createMemoryUsers() {
    final CacheGroup groupBoss = new CacheGroup("BOSS", "BOSS");
    final CacheGroup groupEmployee = new CacheGroup("EMPLOYEE", "EMPLOYEE");

    final CacheUser userA = new CacheUser("111", "Stefan", "Stani",
        "stefan.stani@edu.fh-joanneum.at", Lists.newArrayList(groupEmployee, groupBoss), "hallo");
    final CacheUser userB = new CacheUser("222", "Matthias", "Geisriegler",
        "matthias.geisriegler@edu.fh-joanneum.at", Lists.newArrayList(groupEmployee), "hallo");
    final CacheUser userC = new CacheUser("333", "Robert", "Singer",
        "robert.singer@edu.fh-joanneum.at", Lists.newArrayList(groupBoss), "hallo");

    users = Maps.newHashMap();
    users.put(userA.getUsername(), userA);
    users.put(userB.getUsername(), userB);
    users.put(userC.getUsername(), userC);
  }
}

@@ -926,24 +926,93 @@
 EMPLOYEE%22);%0D
+%0A    final CacheGroup groupAdmin = new CacheGroup(%22ADMIN%22, %22ADMIN%22);%0D
 %0A%0D%0A    final
@@ -1331,16 +1331,28 @@
 Employee
+, groupAdmin
 ), %22hall
@@ -1491,32 +1491,55 @@
 ayList(groupBoss
+, groupBoss, groupAdmin
 ), %22hallo%22);%0D%0A%0D%0A

add admin to matthias