LOGGER.error("Not all required fields completed. Please verify all fields"
+ " have been completed.");
} else
{
LOGGER.debug("All fields complete");
GradedEvent gradedEvent = null;
EntityManager em = emf.createEntityManager();
LOGGER.debug("Getting selected Course");
CourseDAO courseDAO = new CourseDAO(emf.createEntityManager());
Course selectedCourse = (Course) cboCourse.getSelectedItem();
Course course = courseDAO.find(selectedCourse.getId());
//Course course = em.find(Course.class, selectedCourse.getId());
LOGGER.debug("Course Name: " + course.getName());
LOGGER.debug("Querying the data source to see if a GradedEvent "
+ "already exists");
GradedEventDAO gradedEventDAO =
new GradedEventDAO(emf.createEntityManager());
// CriteriaBuilder cb = em.getCriteriaBuilder();
// CriteriaQuery cq = cb.createQuery(GradedEvent.class);
// Root<GradedEvent> gradedEventRoot = cq.from(GradedEvent.class);
// cq.where(cb.and(cb.equal(gradedEventRoot.get("assignment"), txtAssignment.getText().trim()),
// cb.equal(gradedEventRoot.get("term"), txtTerm.getText().trim()),
// cb.equal(gradedEventRoot.get("course"), course),
// cb.equal(gradedEventRoot.get("version"), txtVersion.getText().trim())));
//
// TypedQuery<GradedEvent> gradedEventQuery = em.createQuery(cq);
// LOGGER.debug("Query built");
try
{
//gradedEvent = gradedEventQuery.getSingleResult();
gradedEvent = gradedEventDAO.find(course,
txtAssignment.getText().trim(), txtTerm.getText().trim(),
txtVersion.getText().trim());
} catch (IllegalArgumentException ex)
{
// Because of the check at the beginning of this method, we should
// never reach this point. But just in case...
LOGGER.warn("Invalid value provided. Ensure Course, Term, "
+ "Assignment, and Version are not blank.");
}
if (gradedEvent != null)
{
JOptionPane.showMessageDialog(this, "ERROR: This Graded "
+ "Event already exists in the system.", "ERROR",
JOptionPane.ERROR_MESSAGE);
LOGGER.error("This GradedEvent already exists in the database");
doClose(RET_CANCEL);
} else
{
LOGGER.debug("Creating a new GradedEvent");
EntityTransaction tx = em.getTransaction();
gradedEvent = new GradedEvent();
gradedEvent.setCourse(course);
gradedEvent.setAssignment(txtAssignment.getText().trim());
gradedEvent.setTerm(txtTerm.getText().trim());
gradedEvent.setVersion(txtVersion.getText().trim());
gradedEvent.setPartialCredit(chkPartialCredit.isSelected());
try
{
gradedEvent.setDueDate(txtDueDate.getText().trim());
} catch (IllegalArgumentException ex)
{
LOGGER.warn("Invalid Date Specified. No Due Date Set");
}
LOGGER.debug("Graded Event: " + gradedEvent.toString());
List<Question> objects = lstQuestions.getSelectedValuesList();
LOGGER.debug("Adding " + objects.size() + " Questions to GradedEvent");
int count = 0;
for (int i = 0; i < objects.size(); i++)
{
// TODO: RAGE-24 - Migrate to the QuestionDAO class.
// Action: Update the Question in the current Persistence Context
Question question = objects.get(i);
try
{
question = em.merge(question);
} catch (Exception ex)
{
LOGGER.error("Exception: " + ex.getLocalizedMessage());
tx.rollback();
}
gradedEvent.addQuestion(question);
count++;
}
LOGGER.debug(count + " Questions added. Saving to database");
Long newId;
try