private void processResult( Map<String, Object> dataRow, boolean isSuccess, String id, Error[] errors) throws DataAccessObjectException { // process success vs. error // extract error message from error result if (isSuccess) { writeSuccess(dataRow, id, null); } else { writeError( dataRow, errors == null ? Messages.getString("Visitor.noErrorReceivedMsg") : errors[0].getMessage()); } }
private void writeOutputToWriter(Object[] results, List<Map<String, Object>> dataArray) throws DataAccessObjectException, LoadException { if (results.length != dataArray.size()) { getLogger().fatal(Messages.getString("Visitor.errorResultsLength")); // $NON-NLS-1$ throw new LoadException(Messages.getString("Visitor.errorResultsLength")); } // have to do this because although saveResult and deleteResult // are a) not the same class yet b) not subclassed for (int i = 0; i < results.length; i++) { Map<String, Object> dataRow = dataArray.get(i); String statusMsg = null; if (results instanceof SaveResult[]) { SaveResult saveRes = (SaveResult) results[i]; if (saveRes.getSuccess()) { if (OperationInfo.insert == getConfig().getOperationInfo()) { statusMsg = Messages.getString("DAOLoadVisitor.statusItemCreated"); } else { statusMsg = Messages.getString("DAOLoadVisitor.statusItemUpdated"); } } dataRow.put(Config.STATUS_COLUMN_NAME, statusMsg); processResult(dataRow, saveRes.getSuccess(), saveRes.getId(), saveRes.getErrors()); } else if (results instanceof DeleteResult[]) { DeleteResult deleteRes = (DeleteResult) results[i]; if (deleteRes.getSuccess()) { statusMsg = Messages.getString("DAOLoadVisitor.statusItemDeleted"); } dataRow.put(Config.STATUS_COLUMN_NAME, statusMsg); processResult(dataRow, deleteRes.getSuccess(), deleteRes.getId(), deleteRes.getErrors()); } else if (results instanceof UpsertResult[]) { UpsertResult upsertRes = (UpsertResult) results[i]; if (upsertRes.getSuccess()) { statusMsg = upsertRes.getCreated() ? Messages.getString("DAOLoadVisitor.statusItemCreated") : Messages.getString("DAOLoadVisitor.statusItemUpdated"); } dataRow.put(Config.STATUS_COLUMN_NAME, statusMsg); processResult(dataRow, upsertRes.getSuccess(), upsertRes.getId(), upsertRes.getErrors()); } } }
@Override protected void loadBatch() throws DataAccessObjectException, LoadException { Object[] results = null; try { results = executeClientAction(getController().getPartnerClient(), dynaArray); } catch (ApiFault e) { handleException(e); } catch (ConnectionException e) { handleException(e); } // set the current processed int currentProcessed; try { currentProcessed = getConfig().getInt(LastRun.LAST_LOAD_BATCH_ROW); } catch (ParameterLoadException e) { // if there's a problem getting last batch row, start at the beginning currentProcessed = 0; } currentProcessed += results.length; getConfig().setValue(LastRun.LAST_LOAD_BATCH_ROW, currentProcessed); try { getConfig().saveLastRun(); } catch (IOException e) { String errMsg = Messages.getString("LoadAction.errorLastRun"); getLogger().error(errMsg, e); handleException(errMsg, e); } writeOutputToWriter(results, dataArray); // update Monitor getProgressMonitor().worked(results.length); getProgressMonitor() .setSubTask(getRateCalculator().calculateSubTask(getNumberOfRows(), getNumberErrors())); // now clear the arrays clearArrays(); }