@ResponseStatus(HttpStatus.OK)
public void loadProviderFeed(@RequestParam Long providerId, @RequestParam(required=false, defaultValue="false") String manual, @RequestParam(required=false, defaultValue="true") String register)
throws ParserConfigurationException, SAXException, IOException, Exception {
LOGGER.info("Updating provider with id: " + providerId);
Provider provider = null;
CronTaskReport report = null;
Dump dump = null;
try {
// CRON REPORT
report = cronTaskReportService.create();
provider = this.providerService.getProviderById(providerId, null);
report.setObject_id(providerId);
report.setDate(new Date());
if(("true").equals(manual)) {
report.setType(CronTaskReport.TYPE.INTERNAL_FEED);
} else {
report.setType(CronTaskReport.TYPE.PROVIDER_FEED);
}
report.setDescription(new StringBuffer("Proveedor: ").append(provider.getName()).toString());
// DUMP
dump = this.dumpService.createDump();
String message = "Proceso de importacion del proveedor: " + provider.getName() + " (" +
provider.getId() + "-" + " " + ")";
dump.setDescription(message);
dump.setLaunched(Calendar.getInstance(new Locale("es")).getTime());
dump.setOwner(provider.getId());
dump.setOwnerClass(Provider.class.getName());
this.dumpService.save(dump);
// IMPORT PROVIDER'S SCHOOLS FROM FEED
providerImporter.importSchools(provider, dump);
// Create task to update provider�s schools from other task.
Map<String, String> params = new HashMap<String, String>();
params.put("providerId", String.valueOf(provider.getId()));
worker.addWork("school", "/task/provider/schools", params);
// IMPORT PROVIDER'S COURSES FROM EACH SCHOOL
/*PageManager<School> paginator = new PageManager<School>();
long total = schoolService.countSchoolsByProvider(providerId);
paginator.setOffset(RANGE);
paginator.setStart(0);
paginator.setSize(total);
ArrayList<School> fails = new ArrayList<School>();
for (Integer page : paginator.getTotalPagesIterator()) {
int start = (page - 1) * RANGE;
int end = (page) * RANGE;
Collection<Long> schoolsIds =
/*Collection<School> schools = schoolService.getSchoolsByProvider(providerId,
"updated", null, start, end);
for(School school : schools) {
try {
providerImporter.createLoadTask(provider, school, dump);
} catch(Exception e) {
LOGGER.warning("Error with school: " + school.getName());
LOGGER.warning(StackTraceUtil.getStackTrace(e));
fails.add(school);
}
}
}
// Retries
for(School school : fails) {
providerImporter.createLoadTask(provider, school, dump);
} */
// Set result into report
report.setResult("OK");
} catch(Exception e) {
report.setResult(new StringBuffer("ERROR: ").append(e.getMessage()).toString());
throw e;
} finally {
if("true".equals(register)) {
cronTaskReportService.save(report);
}