2  * Copyright (c) 2016 Inocybe Technologies and others.  All rights reserved.
 
   4  * This program and the accompanying materials are made available under the
 
   5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 
   6  * and is available at http://www.eclipse.org/legal/epl-v10.html
 
   9 package org.opendaylight.aaa.idm.rest.test;
 
  11 import java.util.ArrayList;
 
  12 import java.util.List;
 
  14 import org.opendaylight.aaa.api.IDMStoreException;
 
  15 import org.opendaylight.aaa.api.IIDMStore;
 
  16 import org.opendaylight.aaa.api.model.Domain;
 
  17 import org.opendaylight.aaa.api.model.Domains;
 
  18 import org.opendaylight.aaa.api.model.Grant;
 
  19 import org.opendaylight.aaa.api.model.Grants;
 
  20 import org.opendaylight.aaa.api.model.Role;
 
  21 import org.opendaylight.aaa.api.model.Roles;
 
  22 import org.opendaylight.aaa.api.model.User;
 
  23 import org.opendaylight.aaa.api.model.Users;
 
  25 public class IDMTestStore implements IIDMStore {
 
  27     private List<Domain> domains = new ArrayList<Domain>();
 
  28     private List<Grant> grants = new ArrayList<Grant>();
 
  29     private List<Role> roles = new ArrayList<Role>();
 
  30     private List<User> users = new ArrayList<User>();
 
  32     public IDMTestStore() {
 
  33         // TODO Auto-generated constructor stub
 
  37     public Domain writeDomain(Domain domain) throws IDMStoreException {
 
  38         domain.setDomainid(String.valueOf(domains.size()));
 
  44     public Domain readDomain(String domainid) throws IDMStoreException {
 
  45         for(Domain dom : domains)  {
 
  46             if (dom.getDomainid().equals(domainid)) {
 
  54     public Domain deleteDomain(String domainid) throws IDMStoreException {
 
  55         for(Domain dom : domains)  {
 
  56             if (dom.getDomainid().equals(domainid)) {
 
  65     public Domain updateDomain(Domain domain) throws IDMStoreException {
 
  66         for(Domain dom : domains)  {
 
  67             if (dom.getDomainid().equals(domain.getDomainid())) {
 
  77     public Domains getDomains() throws IDMStoreException {
 
  78         Domains doms =  new Domains();
 
  79         doms.setDomains(domains);
 
  84     public Role writeRole(Role role) throws IDMStoreException {
 
  85         role.setRoleid(String.valueOf(roles.size()));
 
  91     public Role readRole(String roleid) throws IDMStoreException {
 
  92         for (Role role : roles) {
 
  93             if (role.getRoleid().equals(roleid)) {
 
 101     public Role deleteRole(String roleid) throws IDMStoreException {
 
 102         for (Role role : roles) {
 
 103             if (role.getRoleid().equals(roleid)) {
 
 112     public Role updateRole(Role role) throws IDMStoreException {
 
 113         for (Role inRole : roles) {
 
 114             if (inRole.getRoleid().equals(role.getRoleid())) {
 
 115                 roles.remove(inRole);
 
 124     public Roles getRoles() throws IDMStoreException {
 
 125         Roles rols = new Roles();
 
 126         rols.setRoles(roles);
 
 131     public User writeUser(User user) throws IDMStoreException {
 
 132         user.setUserid(String.valueOf(users.size()));
 
 138     public User readUser(String userid) throws IDMStoreException {
 
 139         for(User usr : users) {
 
 140             if (usr.getUserid().equals(userid)) {
 
 148     public User deleteUser(String userid) throws IDMStoreException {
 
 149         for(User usr : users) {
 
 150             if (usr.getUserid().equals(userid)) {
 
 159     public User updateUser(User user) throws IDMStoreException {
 
 160         for(User usr : users) {
 
 161             if (usr.getUserid().equals(user.getUserid())) {
 
 171     public Users getUsers() throws IDMStoreException {
 
 172         Users usrs = new Users();
 
 173         usrs.setUsers(users);
 
 178     public Users getUsers(String username, String domainId) throws IDMStoreException {
 
 179         Users usrs = new Users();
 
 181         Domain domain = null;
 
 182         for(User usr : users) {
 
 183             if (usr.getName().equals(username)) {
 
 188         for(Domain dom : domains) {
 
 189             if (dom.getDomainid().equals(domainId)) {
 
 194         if (user == null || domain == null)
 
 196         for (Grant grant : grants) {
 
 197             if (grant.getUserid().equals(user.getUserid()) && grant.getDomainid().equals(domain.getDomainid())) {
 
 198                 List<User> usrList = new ArrayList<User>();
 
 200                 usrs.setUsers(usrList);
 
 208     public Grant writeGrant(Grant grant) throws IDMStoreException {
 
 209         grant.setGrantid(String.valueOf(grants.size()));
 
 215     public Grant readGrant(String grantid) throws IDMStoreException {
 
 216         for (Grant grant : grants) {
 
 217             if (grant.getGrantid().equals(grantid)) {
 
 225     public Grant deleteGrant(String grantid) throws IDMStoreException {
 
 226         for (Grant grant : grants) {
 
 227             if (grant.getGrantid().equals(grantid)) {
 
 228                 grants.remove(grant);
 
 236     public Grants getGrants(String domainid, String userid) throws IDMStoreException {
 
 237         Grants usrGrants = new Grants();
 
 238         List<Grant> usrGrant = new ArrayList<Grant>();
 
 239         for (Grant grant : grants) {
 
 240             if (grant.getUserid().equals(userid) && grant.getDomainid().equals(domainid)) {
 
 244         usrGrants.setGrants(usrGrant);
 
 249     public Grants getGrants(String userid) throws IDMStoreException {
 
 250         Grants usrGrants = new Grants();
 
 251         List<Grant> usrGrant = new ArrayList<Grant>();
 
 252         for (Grant grant : grants) {
 
 253             if (grant.getUserid().equals(userid)) {
 
 257         usrGrants.setGrants(usrGrant);
 
 262     public Grant readGrant(String domainid, String userid, String roleid) throws IDMStoreException {
 
 263         for (Grant grant : grants) {
 
 264             if (grant.getDomainid().equals(domainid) && grant.getUserid().equals(userid) && grant.getRoleid().equals(roleid)) {