コード例 #1
0
ファイル: FillDatabase.java プロジェクト: Letractively/web-rp
 private void addManager() throws UserNameExistsException {
   User manager = new User();
   manager.setUserName("root");
   manager.setPassword(Hash.hashString("root"));
   manager.setPhoneNumber("0123456789");
   manager.setEmail("*****@*****.**");
   manager.setAddress("Root street 42.");
   userDAO.insertUser(manager);
 }
コード例 #2
0
ファイル: FillDatabase.java プロジェクト: Letractively/web-rp
 private void addUsers() throws IOException {
   RandomAccessFile f = new RandomAccessFile("randomUser.csv", "r");
   String dataString = null;
   ResourceType type = null;
   try {
     type = resourceTypeDAO.getResourceTypeByResourceTypeName("human");
   } catch (Exception e) {
     System.err.println(e);
   }
   ArrayList<Group> groups = null;
   Random random = new Random(1l);
   try {
     groups = groupDAO.getAllGroups();
   } catch (DAOException e1) {
     e1.printStackTrace();
   }
   while ((dataString = f.readLine()) != null) {
     String[] data = dataString.split(";");
     User insert = new User();
     if (data[0].length() < 45) {
       insert.setUserName(data[0]);
     } else {
       insert.setUserName(data[0].substring(0, 44));
     }
     insert.setPassword(Hash.hashString(data[1]));
     if (data[2].length() < 15) {
       insert.setPhoneNumber(data[2]);
     } else {
       insert.setPhoneNumber(data[2].substring(0, 14));
     }
     if (data[3].length() < 45) {
       insert.setEmail(data[3]);
     } else {
       insert.setEmail(data[3].substring(0, 44));
     }
     if (data[4].length() < 45) {
       insert.setAddress(data[4]);
     } else {
       insert.setAddress(data[4].substring(0, 44));
     }
     Resource pair = new Resource();
     pair.setActive(true);
     pair.setDescription("");
     pair.setResourceTypeID(type.getResourceTypeID());
     pair.setResourceName(data[5]);
     System.out.println(insert);
     try {
       userDAO.insertUser(insert);
       resourceDAO.insertResource(pair);
       resourceDAO.linkResourceToUser(pair, insert);
     } catch (Exception e) {
       e.printStackTrace();
     }
     for (int i = 0; i < 3; ++i) {
       try {
         resourceDAO.addResourceToGroup(pair, groups.get(random.nextInt(groups.size())));
       } catch (DAOException e) {
         System.out.println(
             "Resource already added to group, but don't worry, there are plenty to choose from");
       }
     }
   }
   f.close();
 }