+ "Throwing IllegalArgumentException");
throw new IllegalArgumentException("Question Name is null");
} else
{
EntityTransaction tx = em.getTransaction();
GradedEvent result = null;
if (gradedEvent.getId() != null)
{
result = em.find(GradedEvent.class, gradedEvent.getId());
} else
{
try
{
// Build the Query
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<GradedEvent> cq = cb.createQuery(GradedEvent.class);
Root<GradedEvent> gradedEventRoot = cq.from(GradedEvent.class);
cq.where(cb.and(cb.equal(gradedEventRoot.get("course"),
gradedEvent.getCourse()),
cb.equal(gradedEventRoot.get("term"),
gradedEvent.getTerm()),
cb.equal(gradedEventRoot.get("assignment"),
gradedEvent.getAssignment()),
cb.equal(gradedEventRoot.get("version"),
gradedEvent.getVersion())));
TypedQuery<GradedEvent> gradedEventQuery = em.createQuery(cq);
result = gradedEventQuery.getSingleResult();
} catch (NoResultException ex)
{
LOGGER.error("GradedEvent not found in Data Source");
throw new IllegalArgumentException("GradedEvent not found in "
+ "Data Source");
}
}
if (result == null)
{
LOGGER.error("GradedEvent not found in the Data Source");
throw new IllegalArgumentException("GradedEvent not found in the "
+ "Data Source");
}
try
{
// Build the Query
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Question> cq = cb.createQuery(Question.class);
Root<Question> questionRoot = cq.from(Question.class);
cq.where(cb.equal(questionRoot.get("name"), question.getName()));
TypedQuery<Question> questionQuery = em.createQuery(cq);
Question resultQ = questionQuery.getSingleResult();
} catch (NoResultException ex)
{
LOGGER.error("Question not found in Data Source");
throw new IllegalArgumentException("Question not found in "
+ "Data Source");
}
if (!result.getQuestions().contains(question))
{
LOGGER.error("Question not assigned to GradedEvent. Raising "
+ "IllegalArgumentException");
throw new IllegalArgumentException("Question not assigned to "
+ "GradedEvent");
}
result.removeQuestion(question);
tx.begin();
em.merge(result);
tx.commit();
}
}