public void createRoster() {
    empCount = employeeService.countAllEmployees();
    workCount = workShiftService.countAllWorkShifts();
    workShiftList = workShiftService.findAllWorkShifts();
    employeeList = employeeService.findAllEmployees();
    workCountint = Integer.valueOf(workCount.intValue());
    empCountint = Integer.valueOf(empCount.intValue());

    InputStream inputStream = null;
    //		Resource resource = null;

    ClassPathResource cpr = new ClassPathResource("META-INF/myconfig.xml");
    try {
      inputStream = cpr.getInputStream();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    //		try {
    //			resource = new FileSystemResource(
    //					"src/main/resources/META-INF/myconfig.xml");
    //			inputStream = resource.getInputStream();
    //		} catch (Exception ex) {
    //			ex.printStackTrace();
    //		}

    SolverFactory solverFactory = new XmlSolverFactory().configure(inputStream);
    Solver solver = solverFactory.buildSolver();
    ShiftAssignment unsolvedShiftAssignment =
        new ShiftAssignmentGenerator()
            .createShiftAssignment(workCountint, empCountint, workShiftList, employeeList);
    // Solve the problem
    solver.setPlanningProblem(unsolvedShiftAssignment);
    solver.solve();
    ShiftAssignment solvedShiftAssignment = (ShiftAssignment) solver.getBestSolution();
    System.out.println(
        "\nSolved shiftRoster wioth 4 departments and 1oo employees:\n"
            + "  Employee Details \t    ShiftPref \t assigned \t RequiredGrade \t EmployeeGrade :\n"
            + toDisplayString(solvedShiftAssignment));
    persistWorkShift(solvedShiftAssignment);
  }
  public void persistWorkShift(ShiftAssignment shiftAssignment) {
    Date today = new Date();

    for (WorkShift workShift : shiftAssignment.getWorkShiftList()) {

      Shift shift = new Shift();
      shift.setShiftDate(today);
      shiftService.saveShift(shift);
      workShift = workShiftService.findWorkShift(workShift.getId());
      shift.setWorkShift(workShift);

      shiftService.updateShift(shift);
      Long workshiftId = workShift.getId();
      Long shiftId = shift.getId();
      persistEmployeeShift(shiftAssignment, shiftId, workshiftId);
    }
  }