private void processImportRequest(ImportRequest request) throws Exception {
   ImportResult result = request.getResult();
   try {
     result.setStatusMessage("Processing CSV data");
     result.setDomain(request.getDomain());
     importLogger.saveImportResult(result);
     if (request.getDomain().equals(Task.PROVIDER_STRING)) {
       List<Task> tasks =
           admin.importProviders(request.getCsvData(), request.getFieldList(), result);
       result.setStatusMessage("Saving changes to database for providers");
       handleTaskList(tasks, result, request);
     } else if (request.getDomain().equals(Task.ORGANISATION_STRING)) {
       List<Task> tasks =
           admin.importOrganisations(request.getCsvData(), request.getFieldList(), result);
       result.setStatusMessage("Saving changes to database for organisations");
       handleTaskList(tasks, result, request);
     }
     result.setStatusMessage("Complete");
     result.setEndDate(new Date());
     importLogger.saveImportResult(result);
     entitySearcher.rebuildSearchindex();
   } catch (Exception e) {
     logger.error("Error processing import", e);
     result.setStatusMessage("Failed");
     result.setException(e);
     result.setErrorMessage(e.getMessage());
     importLogger.saveImportResult(result);
     throw e;
   }
 }
 private void handleTaskList(List<Task> tasks, ImportResult result, ImportRequest request)
     throws Exception {
   importLogger.saveImportResult(result);
   boolean flushAndClear = false;
   for (int i = 0; i < tasks.size(); i++) {
     flushAndClear = false;
     if (i != 0 && i % 25 == 0) {
       flushAndClear = true;
     }
     Task task = tasks.get(i);
     controller.handleTask(
         task, request.getUser(), request.getIp(), request.getSessionId(), flushAndClear);
     result.setProcessed(result.getProcessed() + 1);
     importLogger.saveImportResult(result);
   }
 }