package ch.heigvd.amt.amtproject.services;

import ch.heigvd.amt.amtproject.model.entities.*;
import ch.heigvd.amt.amtproject.services.dao.ApplicationDAOLocal;
import ch.heigvd.amt.amtproject.services.dao.UserDAOLocal;

import ch.heigvd.amt.amtproject.services.dao.ApiKeyDAOLocal;
import ch.heigvd.amt.amtproject.services.dao.EndUserDAOLocal;
import ch.heigvd.amt.amtproject.services.dao.RoleDAOLocal;

import javax.ejb.EJB;
import javax.ejb.Stateless;

@Stateless
public class TestDataManager implements TestDataManagerLocal {
    
    @EJB
    UserDAOLocal userDAO;
    
    @EJB
    ApplicationDAOLocal applicationDAO;
    
    @EJB
    ApiKeyDAOLocal apiKeyDAO;
    
    @EJB
    RoleDAOLocal roleDAO;
 
    @EJB
    EndUserDAOLocal enduUserDAO;

    @Override
    public void generateTestData() {
        Account u = new Account("test@t.com", "t", "t", "t");
        Account u2 = new Account("marc@heig-vd.ch", "Marc", "Pellet", "bonjour");
        
        userDAO.create(u);
        userDAO.create(u2);
        
        ApiKey key1 = new ApiKey();
        ApiKey key2 = new ApiKey();
        ApiKey key3 = new ApiKey();
        
        apiKeyDAO.create(key1);
        apiKeyDAO.create(key2);
        apiKeyDAO.create(key3);
        
        
        
        Application a1 = new Application(key1, u, "app1", "c'est la première app", true);
        Application a2 = new Application(key2, u2, "app2", "c'est une autre app", true);
        Application a3 = new Application(key3, u, "app3", "Et bim une troisième app", false);
        
        applicationDAO.create(a1);
        applicationDAO.create(a2);
        applicationDAO.create(a3);
        
        for(int i = 0; i < 154; i++){
            createEndUser(a3);
            createEndUser(a1);
            createEndUser(a2);
        }
           
        //UserRole r1 = new UserRole("admin");
        //UserRole r2 = new UserRole("developper");
        
        //roleDAO.create(r1);
        //roleDAO.create(r2);
    }
    
    private void createEndUser(Application app){
        EndUser e = new EndUser();
        e.setApp(app);
        enduUserDAO.create(e);
    }

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    
    
}

@@ -87,16 +87,75 @@
 ties.*;%0A
+import ch.heigvd.amt.amtproject.rest.dto.BadgeCreationDTO;%0A
 import c
@@ -204,32 +204,32 @@
 cationDAOLocal;%0A
-
 import ch.heigvd
@@ -445,32 +445,157 @@
 ao.RoleDAOLocal;
+%0Aimport ch.heigvd.amt.amtproject.services.dao.rest.BadgeDAO;%0Aimport ch.heigvd.amt.amtproject.services.dao.rest.BadgeDAOLocal;
 %0A%0Aimport javax.e
@@ -883,31 +883,24 @@
 oleDAO;%0A
- %0A    
+%0A%09
 @EJB%0A
-    
+%09
 EndUserD
@@ -921,16 +921,53 @@
 erDAO;%0A%0A
+%09@EJB%0A%09BadgeDAOLocal badgeDAOLocal;%0A%0A
     @Ove
@@ -1251,32 +1251,70 @@
 y1 = new ApiKey(
+%22c45e61bf-dbf1-4404-bf6d-7fcbb83d4d26%22
 );%0A        ApiKe
@@ -2041,27 +2041,275 @@
       %7D%0A
-           
+%0A%09%09Badge b1 = new Badge(%22Test1%22, %22https://playfoursquare.s3.amazonaws.com/badge/300/local.png%22, a1);%0A%09%09Badge b2 = new Badge(%22Test2%22, %22https://playfoursquare.s3.amazonaws.com/badge/300/newbie.png%22, a1);%0A%0A%09%09badgeDAOLocal.create(b1);%0A%09%09badgeDAOLocal.create(b2);%0A
 %0A       

Add Test Badges