Example #1
0
 private void addResources() throws IOException {
   RandomAccessFile f = new RandomAccessFile("randomResource.csv", "r");
   String dataString = null;
   ResourceType type = null;
   while ((dataString = f.readLine()) != null) {
     String[] data = dataString.split(";");
     Resource insert = new Resource();
     if (data[0].length() < 45) {
       insert.setResourceName(data[0]);
     } else {
       insert.setResourceName(data[0].substring(0, 44));
     }
     try {
       insert.setResourceTypeID(
           resourceTypeDAO.getResourceTypeByResourceTypeName(data[1]).getResourceTypeID());
     } catch (Exception e1) {
       e1.printStackTrace();
     }
     insert.setDescription("");
     insert.setActive(true);
     System.out.println(insert);
     try {
       resourceDAO.insertResource(insert);
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
   f.close();
 }
Example #2
0
 private void addWorkers() {
   ResourceType type;
   ArrayList<Resource> users = null;
   ArrayList<Project> projects = null;
   Random random = new Random(1l);
   try {
     type = resourceTypeDAO.getResourceTypeByResourceTypeName("human");
     users = resourceDAO.getResourcesByResourceType(type);
     projects = projectDAO.getAllProjects();
   } catch (Exception e) {
     e.printStackTrace();
   }
   for (Project project : projects) {
     int workers = random.nextInt(11) + 5;
     Resource user = users.get(random.nextInt(users.size()));
     try {
       resourceDAO.insertUserTask(user.getResourceID(), project.getProjectID(), true);
     } catch (UserWorkOnThisProjectException e) {
       e.printStackTrace();
     }
     for (int i = 0; i < workers; ++i) {
       user = users.get(random.nextInt(users.size()));
       try {
         resourceDAO.insertUserTask(
             user.getResourceID(), project.getProjectID(), (random.nextInt(5) == 0));
       } catch (UserWorkOnThisProjectException e) {
         System.out.println(
             "User already assigned, but don't worry, there are plenty to choose from");
       }
     }
   }
 }
Example #3
0
  private void addNonHumanBookings() {
    ArrayList<Resource> resources = null;
    Random random = new Random(1l);
    try {
      resources =
          resourceDAO.getResourcesByResourceType(
              resourceTypeDAO.getResourceTypeByResourceTypeName("machine"));
      resources.addAll(
          resourceDAO.getResourcesByResourceType(
              resourceTypeDAO.getResourceTypeByResourceTypeName("room")));
    } catch (Exception e) {
      e.printStackTrace();
    }
    ArrayList<Project> allProjects = null;
    try {
      allProjects = projectDAO.getAllProjects();
    } catch (Exception e) {
      e.printStackTrace();
    }
    for (Resource resource : resources) {
      HashSet<Project> projects = new HashSet<Project>();
      for (int i = 0; i < 3; ++i) {
        projects.add(allProjects.get(random.nextInt(allProjects.size())));
      }

      int max = (projects.size() > 0) ? (50 / projects.size()) : 0;
      for (Project project : projects) {
        for (int i = project.getStartWeek(); i <= project.getDeadLine(); ++i) {
          if (random.nextInt(2) == 0) {
            Booking booking = new Booking();
            booking.setProjectID(project.getProjectID());
            booking.setResourceID(resource.getResourceID());
            booking.setWeek(i);
            booking.setRatio(((float) (random.nextInt(max + 1) + max)) / 100);
            try {
              bookingDAO.insertBooking(booking);
            } catch (DAOException e) {
              e.printStackTrace();
            }
            System.out.println(booking);
          }
        }
      }
    }
  }
Example #4
0
 private void addHumanBookings() {
   ArrayList<Resource> workers = null;
   Random random = new Random(1l);
   try {
     workers =
         resourceDAO.getResourcesByResourceType(
             resourceTypeDAO.getResourceTypeByResourceTypeName("human"));
   } catch (Exception e) {
     e.printStackTrace();
   }
   for (Resource worker : workers) {
     ArrayList<Project> projects = null;
     try {
       projects = projectDAO.getProjectsByWorker(worker);
     } catch (Exception e) {
       e.printStackTrace();
     }
     int max = (projects.size() > 0) ? (50 / projects.size()) : 0;
     for (Project project : projects) {
       for (int i = project.getStartWeek(); i <= project.getDeadLine(); ++i) {
         if (random.nextInt(2) == 0) {
           Booking booking = new Booking();
           booking.setProjectID(project.getProjectID());
           booking.setResourceID(worker.getResourceID());
           booking.setWeek(i);
           booking.setRatio(((float) (random.nextInt(max + 1) + max)) / 100);
           try {
             bookingDAO.insertBooking(booking);
           } catch (DAOException e) {
             e.printStackTrace();
           }
           System.out.println(booking);
         }
       }
     }
   }
 }
Example #5
0
 public FillDatabase() {
   try {
     //			addStatuses();
     //			addProjects();
     //			addResourceTypes();
     //			addGroups();
     //			addUsers();
     //			addWorkers();
     //			addResources();
     //			addHumanBookings();
     //			addNonHumanBookings();
     //			addManager();
     addDescriptions();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Example #6
0
 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();
 }