private void selectiveCourseStore(Course newCourse, Locale locale)
throws NotSameClassException, Exception {
newCourse.setCreated(Calendar.getInstance(new Locale("es")).getTime());
newCourse.setUpdated(newCourse.getCreated());
Course oldCourse = this.courseService.getCourseByExternalId(newCourse.getExternalId(), locale);
if(oldCourse == null) { // Alta nueva: el curso no estaba registrado en la base de datos.
LOGGER.info("Curso NO existente: (" + locale.getLanguage() + ")" + newCourse.getTitle());
LOGGER.info("NewCourse: " + newCourse.toString());
newCourse.setActive(true);
this.entities.add(newCourse);
} else if(!oldCourse.equals(newCourse) || !oldCourse.isTranslated()) {
//CourseComparator comparator = new CourseComparator();
/*if(comparator.compare(newCourse, oldCourse) == 0) {
LOGGER.info("Curso existente y NO MODIFICADO");
return;
} */
LOGGER.info("Curso existente y MODIFICADO " + "(" + locale.getLanguage() + ")");
LOGGER.info("OldCourse: " + oldCourse.toString());
LOGGER.info("NewCourse: " + newCourse.toString());
/*Modificacion: el curso estaba registrado en la base de datos, pero se modifica.*/
/*Set<String> properties = new HashSet<String>();
properties.add("externalId");
properties.add("title");
properties.add("url");
properties.add("start");
properties.add("end");
properties.add("information");
properties.add("active");
this.beanManager.mergeObjects(newCourse, oldCourse, properties);*/
oldCourse.setTitle(newCourse.getTitle());
oldCourse.setUrl(newCourse.getUrl());
oldCourse.setStart(newCourse.getStart());
oldCourse.setEnd(newCourse.getEnd());
oldCourse.setInformation(newCourse.getInformation());
oldCourse.setTags(newCourse.getTags());
oldCourse.setActive(true);
if(oldCourse.isTranslated()) oldCourse.setUpdated(Calendar.getInstance(new Locale("es")).getTime());
//newCourse.setId(oldCourse.getId());
//newCourse.setCreated(oldCourse.getCreated());
//newCourse.setUpdated(oldCourse.getUpdated());
this.entities.add(oldCourse);
LOGGER.info("Se guarda este: (" + locale.getLanguage() + ")" + oldCourse.toString());
} else {
LOGGER.info("Curso existente y NO MODIFICADO ID:" + oldCourse.getId());
}
}