private void selectiveSchoolStore(School newSchool, Locale locale)
throws NotSameClassException, Exception {
newSchool.setCreated(Calendar.getInstance(new Locale("es")).getTime());
newSchool.setUpdated(newSchool.getCreated());
School oldSchool;
oldSchool = this.schoolService.getSchoolByExternalId(newSchool.getExternalId(), locale);
if(oldSchool == null) {
// Creacion de un centro nuevo.
LOGGER.info("Adding new school: " + newSchool.getName());
this.entities.add(newSchool);
} else {
// Actualizacion de un centro existente.
// Logica de actualizacion
SchoolComparator comparator = new SchoolComparator();
if(comparator.compare(newSchool, oldSchool) == 0) {
LOGGER.info("Existing school but NOT MODIFIED");
return;
}
LOGGER.severe("Existing school but MODIFIED");
Set<String> properties = new HashSet<String>();
properties.add("telephone");
properties.add("fax");
properties.add("zipCode");
properties.add("webSite");
properties.add("streetAddress");
properties.add("city");
properties.add("email");
this.beanManager.mergeObjects(newSchool.getContactInfo(),
oldSchool.getContactInfo(), properties);
properties = new HashSet<String>();
properties.add("externalId");
properties.add("name");
properties.add("feed");
this.beanManager.mergeObjects(newSchool, oldSchool, properties);
//newSchool.setId(oldSchool.getId());
//newSchool.setCreated(oldSchool.getCreated());
oldSchool.setUpdated(Calendar.getInstance(new Locale("es")).getTime());
//newSchool.setUpdated(oldSchool.getUpdated());
this.entities.add(oldSchool);
}
}