ProcessDefinition definition = getProcessDefinition();
List<ActivityDefinition> list = jpaTemplate.find("select x from " + ActivityDefinition.class.getName() + " x where x.processDefinition = ?1 and x.name = ?2", definition, activityName);
if (!list.isEmpty()) {
return list.get(0);
} else {
ActivityDefinition answer = new ActivityDefinition();
answer.setName(activityName);
answer.setProcessDefinition(ProcessDefinition.getRefreshedProcessDefinition(jpaTemplate, definition));
jpaTemplate.persist(answer);
return answer;
}
}