Skip to content

Commit

Permalink
prefix all property names with "PROP_" for code maintainability
Browse files Browse the repository at this point in the history
prefix all property names with "PROP_" for code maintainability
  • Loading branch information
ashitsalesforce committed Oct 14, 2024
1 parent 384630d commit 2532ee1
Show file tree
Hide file tree
Showing 78 changed files with 1,024 additions and 893 deletions.
30 changes: 15 additions & 15 deletions src/main/java/com/salesforce/dataloader/action/AbstractAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ protected AbstractAction(Controller controller, ILoaderProgress monitor)
}
this.visitor = createVisitor();
int retries = -1;
this.enableRetries = controller.getAppConfig().getBoolean(AppConfig.ENABLE_RETRIES);
this.enableRetries = controller.getAppConfig().getBoolean(AppConfig.PROP_ENABLE_RETRIES);
if (this.enableRetries) {
try {
// limit the number of max retries in case limit is exceeded
retries = Math.min(AppConfig.MAX_RETRIES_LIMIT, controller.getAppConfig().getInt(AppConfig.MAX_RETRIES));
retries = Math.min(AppConfig.MAX_RETRIES_LIMIT, controller.getAppConfig().getInt(AppConfig.PROP_MAX_RETRIES));
} catch (ParameterLoadException e) {
retries = AppConfig.DEFAULT_MAX_RETRIES;
}
Expand Down Expand Up @@ -158,7 +158,7 @@ public final void execute() {
private List<Exception> executeOperation() {
List<Exception> exceptions = new ArrayList<>();
try {
getLogger().info(getMessage("loading", getConfig().getString(AppConfig.OPERATION)));
getLogger().info(getMessage("loading", getConfig().getString(AppConfig.PROP_OPERATION)));
getDao().open();
initOperation();
if (writeStatus()) {
Expand Down Expand Up @@ -189,7 +189,7 @@ private List<Exception> executeOperation() {
//if no exceptions occurred then display success/error
if (exceptions.size() == 0) {
final Object[] args = {String.valueOf(getVisitor().getNumberSuccesses()),
getConfig().getString(AppConfig.OPERATION), String.valueOf(getVisitor().getNumberErrors())};
getConfig().getString(AppConfig.PROP_OPERATION), String.valueOf(getVisitor().getNumberErrors())};

// set the monitor to done
if (getMonitor().isCanceled()) {
Expand All @@ -213,7 +213,7 @@ private boolean shouldRetryOperation(Exception e, int numAttempts) {
if (numAttempts < this.maxRetries-1 && this.enableRetries) {
// loop only if less than MAX_RETRIES
logger.warn("Encountered an error on server when performing "
+ controller.getAppConfig().getString(AppConfig.OPERATION)
+ controller.getAppConfig().getString(AppConfig.PROP_OPERATION)
+ " on attempt "
+ numAttempts );
logger.warn(e.getMessage());
Expand All @@ -230,7 +230,7 @@ private boolean shouldRetryOperation(Exception e, int numAttempts) {
private void retrySleep(int retryNum) {
int sleepSecs;
try {
sleepSecs = controller.getAppConfig().getInt(AppConfig.MIN_RETRY_SLEEP_SECS);
sleepSecs = controller.getAppConfig().getInt(AppConfig.PROP_MIN_RETRY_SLEEP_SECS);
} catch (ParameterLoadException e1) {
sleepSecs = AppConfig.DEFAULT_MIN_RETRY_SECS;
}
Expand All @@ -239,7 +239,7 @@ private void retrySleep(int retryNum) {

logger.info(Messages.getFormattedString("Client.retryOperation",
new String[]{Integer.toString(retryNum + 1),
getController().getAppConfig().getString(AppConfig.OPERATION),
getController().getAppConfig().getString(AppConfig.PROP_OPERATION),
Integer.toString(sleepSecs)}));
try {
Thread.sleep(sleepSecs * 1000);
Expand Down Expand Up @@ -310,7 +310,7 @@ protected void handleException(Exception e) {
* @throws DataAccessObjectInitializationException
*/
public DataWriter createErrorWriter() throws DataAccessObjectInitializationException {
final String filename = getConfig().getString(AppConfig.OUTPUT_ERROR);
final String filename = getConfig().getString(AppConfig.PROP_OUTPUT_ERROR);
if (filename == null || filename.length() == 0)
throw new DataAccessObjectInitializationException(getMessage("errorMissingErrorFile"));
// TODO: Make sure that specific DAO is not mentioned: use DataReader, DataWriter, or DataAccessObject
Expand All @@ -323,7 +323,7 @@ public DataWriter createErrorWriter() throws DataAccessObjectInitializationExcep
* @throws DataAccessObjectInitializationException
*/
public DataWriter createSuccesWriter() throws DataAccessObjectInitializationException {
final String filename = getConfig().getString(AppConfig.OUTPUT_SUCCESS);
final String filename = getConfig().getString(AppConfig.PROP_OUTPUT_SUCCESS);
if (filename == null || filename.length() == 0)
throw new DataAccessObjectInitializationException(getMessage("errorMissingSuccessFile"));
// TODO: Make sure that specific DAO is not mentioned: use DataReader, DataWriter, or DataAccessObject
Expand All @@ -336,8 +336,8 @@ public void openErrorWriter(List<String> headers) throws OperationException {
AppConfig appConfig = this.controller.getAppConfig();

if (appConfig.isBulkV2APIEnabled()
&& !appConfig.getString(AppConfig.OPERATION).equals(OperationInfo.extract.name())
&& !appConfig.getString(AppConfig.OPERATION).equals(OperationInfo.extract_all.name())) {
&& !appConfig.getString(AppConfig.PROP_OPERATION).equals(OperationInfo.extract.name())
&& !appConfig.getString(AppConfig.PROP_OPERATION).equals(OperationInfo.extract_all.name())) {
headers.add(0, AppConfig.ID_COLUMN_NAME);
headers.add(1, AppConfig.ERROR_COLUMN_NAME);
} else {
Expand All @@ -349,7 +349,7 @@ public void openErrorWriter(List<String> headers) throws OperationException {
getErrorWriter().setColumnNames(headers);
} catch (final DataAccessObjectInitializationException e) {
throw new OperationException(
getMessage("errorOpeningErrorFile", getConfig().getString(AppConfig.OUTPUT_ERROR)), e);
getMessage("errorOpeningErrorFile", getConfig().getString(AppConfig.PROP_OUTPUT_ERROR)), e);
}
}

Expand All @@ -359,8 +359,8 @@ public void openSuccessWriter(List<String> headers) throws LoadException {

// add the ID column if not there already
if (appConfig.isBulkV2APIEnabled()
&& !appConfig.getString(AppConfig.OPERATION).equals(OperationInfo.extract.name())
&& !appConfig.getString(AppConfig.OPERATION).equals(OperationInfo.extract_all.name())) {
&& !appConfig.getString(AppConfig.PROP_OPERATION).equals(OperationInfo.extract.name())
&& !appConfig.getString(AppConfig.PROP_OPERATION).equals(OperationInfo.extract_all.name())) {
if (headers.size() == 0 || !AppConfig.ID_COLUMN_NAME.equals(headers.get(0))) {
headers.add(0, AppConfig.ID_COLUMN_NAME);
}
Expand All @@ -376,7 +376,7 @@ public void openSuccessWriter(List<String> headers) throws LoadException {
getSuccessWriter().setColumnNames(headers);
} catch (final DataAccessObjectInitializationException e) {
throw new LoadException(
getMessage("errorOpeningSuccessFile", getConfig().getString(AppConfig.OUTPUT_SUCCESS)), e);
getMessage("errorOpeningSuccessFile", getConfig().getString(AppConfig.PROP_OUTPUT_SUCCESS)), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ protected boolean visit() throws OperationException, DataAccessObjectException,

@Override
protected boolean writeStatus() {
return getConfig().getBoolean(AppConfig.LIMIT_OUTPUT_TO_QUERY_FIELDS) && getConfig().getBoolean(AppConfig.ENABLE_EXTRACT_STATUS_OUTPUT);
return getConfig().getBoolean(AppConfig.PROP_LIMIT_OUTPUT_TO_QUERY_FIELDS) && getConfig().getBoolean(AppConfig.PROP_ENABLE_EXTRACT_STATUS_OUTPUT);
}

@Override
protected void checkDao(DataAccessObject dao) throws DataAccessObjectInitializationException {
if (!(dao instanceof DataWriter)) {
final String errMsg = getMessage("errorWrongDao", getConfig().getString(AppConfig.DAO_TYPE),
final String errMsg = getMessage("errorWrongDao", getConfig().getString(AppConfig.PROP_DAO_TYPE),
DataAccessObjectFactory.CSV_WRITE_TYPE + " or " + DataAccessObjectFactory.DATABASE_WRITE_TYPE,
getConfig().getString(AppConfig.OPERATION));
getConfig().getString(AppConfig.PROP_OPERATION));
getLogger().fatal(errMsg);
throw new DataAccessObjectInitializationException(errMsg);
}
Expand All @@ -86,7 +86,7 @@ public IQueryVisitor getVisitor() {
}

private List<String> getDaoColumnsFromMapper() {
((SOQLMapper)getController().getMapper()).initSoqlMapping(getConfig().getString(AppConfig.EXTRACT_SOQL));
((SOQLMapper)getController().getMapper()).initSoqlMapping(getConfig().getString(AppConfig.PROP_EXTRACT_SOQL));
return ((SOQLMapper)getController().getMapper()).getDaoColumnsForSoql();
}

Expand Down Expand Up @@ -137,13 +137,13 @@ protected List<String> getStatusColumns() throws ExtractException {
@Override
protected void initOperation() throws DataAccessObjectInitializationException, OperationException {
((SOQLMapper)getController().getMapper()).clearMappings();
if (getController().getAppConfig().getBoolean(AppConfig.LIMIT_OUTPUT_TO_QUERY_FIELDS)) {
if (getController().getAppConfig().getBoolean(AppConfig.PROP_LIMIT_OUTPUT_TO_QUERY_FIELDS)) {
final List<String> daoColumns = getDaoColumnsFromMapper();
getDao().setColumnNames(daoColumns);
} else {
// check for syntactical correctness and presence of nested soql.
// nested soql is currently not supported.
((SOQLMapper)getController().getMapper()).parseSoql(getConfig().getString(AppConfig.EXTRACT_SOQL));
((SOQLMapper)getController().getMapper()).parseSoql(getConfig().getString(AppConfig.PROP_EXTRACT_SOQL));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ protected AbstractLoadAction(Controller controller, ILoaderProgress monitor)
@Override
protected void checkDao(DataAccessObject dao) throws DataAccessObjectInitializationException {
if (!(dao instanceof DataReader)) {
final String errMsg = getMessage("errorWrongDao", getConfig().getString(AppConfig.DAO_TYPE),
final String errMsg = getMessage("errorWrongDao", getConfig().getString(AppConfig.PROP_DAO_TYPE),
DataAccessObjectFactory.CSV_READ_TYPE + " or " + DataAccessObjectFactory.DATABASE_READ_TYPE,
getConfig().getString(AppConfig.OPERATION));
getConfig().getString(AppConfig.PROP_OPERATION));
getLogger().fatal(errMsg);
throw new DataAccessObjectInitializationException(errMsg);
}
Expand Down Expand Up @@ -111,7 +111,7 @@ protected void initOperation() throws MappingInitializationException, DataAccess
// ensure all field mappings are valid before data load
((LoadMapper)this.getController().getMapper()).verifyMappingsAreValid();
// start the Progress Monitor
getMonitor().beginTask(getMessage("loading", getConfig().getString(AppConfig.OPERATION)), getDao().getTotalRows());
getMonitor().beginTask(getMessage("loading", getConfig().getString(AppConfig.PROP_OPERATION)), getDao().getTotalRows());
// set the starting row
DAORowUtil.get().skipRowToStartOffset(getConfig(), getDao(), getMonitor(), !getConfig().isBulkAPIEnabled());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public DeleteAction(Controller controller, ILoaderProgress monitor) throws DataA
@Override
protected DAOLoadVisitor createVisitor() {
if (getController().getAppConfig().isRESTAPIEnabled()
&& getController().getAppConfig().getBoolean(AppConfig.DELETE_WITH_EXTERNALID)) {
&& getController().getAppConfig().getBoolean(AppConfig.PROP_DELETE_WITH_EXTERNALID)) {
return new RESTDeleteVisitor(getController(), getMonitor(), getSuccessWriter(), getErrorWriter());
} else {
return new PartnerDeleteVisitor(getController(), getMonitor(), getSuccessWriter(), getErrorWriter());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public AbstractQueryVisitor(AbstractExtractAction action, Controller controller,
DataWriter successWriter, DataWriter errorWriter) {
super(controller, monitor, successWriter, errorWriter);
this.queryWriter = queryWriter;
this.soql = getConfig().getString(AppConfig.EXTRACT_SOQL);
this.soql = getConfig().getString(AppConfig.PROP_EXTRACT_SOQL);
this.batchRows = new ArrayList<Row>();
this.batchIds = new ArrayList<String>();
this.batchSize = getWriteBatchSize();
Expand Down Expand Up @@ -115,7 +115,7 @@ protected abstract void writeExtraction() throws AsyncApiException, ExtractExcep

@Override
protected boolean writeStatus() {
return getConfig().getBoolean(AppConfig.ENABLE_EXTRACT_STATUS_OUTPUT);
return getConfig().getBoolean(AppConfig.PROP_ENABLE_EXTRACT_STATUS_OUTPUT);
}

private String getSoql() {
Expand All @@ -127,7 +127,7 @@ private DataWriter getQueryWriter() {
}

protected void addResultRow(Row row, String id) throws DataAccessObjectException {
if (controller.getAppConfig().getBoolean(AppConfig.INCLUDE_RICH_TEXT_FIELD_DATA_IN_QUERY_RESULTS)) {
if (controller.getAppConfig().getBoolean(AppConfig.PROP_INCLUDE_RICH_TEXT_FIELD_DATA_IN_QUERY_RESULTS)) {
getRTFDataForRow(row);
}
this.batchRows.add(row);
Expand Down Expand Up @@ -199,7 +199,7 @@ private String getBinaryContentForURL(String urlStr, String fieldName) {
+ "/services/data/v"
+ Controller.getAPIVersion()
+ "/sobjects/"
+ controller.getAppConfig().getString(AppConfig.ENTITY)
+ controller.getAppConfig().getString(AppConfig.PROP_ENTITY)
+ "/"
+ sobjectId
+ "/richTextImageFields/"
Expand Down Expand Up @@ -231,15 +231,15 @@ private void writeBatch() throws DataAccessObjectException {
writeSuccesses();
} else {
writeErrors(Messages.getMessage(getClass(), "statusErrorNotWritten",
getConfig().getString(AppConfig.DAO_NAME)));
getConfig().getString(AppConfig.PROP_DAO_NAME)));
}
getProgressMonitor().worked(this.batchRows.size());
getProgressMonitor().setSubTask(getRateCalculator().calculateSubTask(getNumberOfRows(), getNumberErrors()));
} catch (final DataAccessObjectInitializationException ex) {
throw ex;
} catch (final DataAccessObjectException ex) {
writeErrors(Messages.getMessage(getClass(), "statusErrorNotWrittenException",
getConfig().getString(AppConfig.DAO_NAME), ex.getMessage()));
getConfig().getString(AppConfig.PROP_DAO_NAME), ex.getMessage()));
} finally {
this.batchRows.clear();
this.batchIds.clear();
Expand All @@ -263,7 +263,7 @@ private void writeErrors(String errorMessage) throws DataAccessObjectException {
protected int getWriteBatchSize() {
int daoBatchSize;
try {
daoBatchSize = getConfig().getInt(AppConfig.DAO_WRITE_BATCH_SIZE);
daoBatchSize = getConfig().getInt(AppConfig.PROP_DAO_WRITE_BATCH_SIZE);
if (daoBatchSize > AppConfig.MAX_DAO_WRITE_BATCH_SIZE) {
daoBatchSize = AppConfig.MAX_DAO_WRITE_BATCH_SIZE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ protected DAOLoadVisitor(Controller controller, ILoaderProgress monitor, DataWri

this.batchSize = getConfig().getImportBatchSize();
rowConversionFailureMap = new HashMap<Integer, Boolean>();
String newRichTextRegex = getConfig().getString(AppConfig.RICH_TEXT_FIELD_REGEX);
String newRichTextRegex = getConfig().getString(AppConfig.PROP_RICH_TEXT_FIELD_REGEX);
if (newRichTextRegex != null && !newRichTextRegex.isBlank()) {
this.richTextRegex = newRichTextRegex;
}
Expand All @@ -127,7 +127,7 @@ public void setRowConversionStatus(int dataSourceRow, boolean conversionSuccess)
protected boolean isRowConversionSuccessful() {
if (!gotSkippedRowsCount) {
try {
skippedRowsCount = controller.getAppConfig().getInt(AppConfig.LOAD_ROW_TO_START_AT);
skippedRowsCount = controller.getAppConfig().getInt(AppConfig.PROP_LOAD_ROW_TO_START_AT);
gotSkippedRowsCount = true;
} catch (ParameterLoadException e) {
// @ignored
Expand All @@ -153,13 +153,13 @@ public boolean visit(Row row) throws OperationException, DataAccessObjectExcepti
// the result are sforce fields mapped to data
Row sforceDataRow = getMapper().mapData(row);

if (this.getConfig().getBoolean(AppConfig.TRUNCATE_FIELDS)
if (this.getConfig().getBoolean(AppConfig.PROP_TRUNCATE_FIELDS)
&& this.getConfig().isRESTAPIEnabled()
&& "update".equalsIgnoreCase(this.getConfig().getString(AppConfig.OPERATION))) {
&& "update".equalsIgnoreCase(this.getConfig().getString(AppConfig.PROP_OPERATION))) {
PartnerClient partnerClient = this.getController().getPartnerClient();
if (cachedFieldAttributesForOperation == null) {
cachedFieldAttributesForOperation = partnerClient.getSObjectFieldAttributesForRow(
this.getConfig().getString(AppConfig.ENTITY), sforceDataRow);
this.getConfig().getString(AppConfig.PROP_ENTITY), sforceDataRow);
}
for (Map.Entry<String, Object> field : sforceDataRow.entrySet()) {
for (Field fieldDescribe : cachedFieldAttributesForOperation) {
Expand Down Expand Up @@ -270,7 +270,7 @@ public void flushRemaining() throws OperationException, DataAccessObjectExceptio

public void clearArrays() {
// clear the arrays
if (!controller.getAppConfig().getBoolean(AppConfig.BULK_API_ENABLED)) {
if (!controller.getAppConfig().getBoolean(AppConfig.PROP_BULK_API_ENABLED)) {
daoRowList.clear();
}
dynaArray.clear();
Expand Down Expand Up @@ -359,7 +359,7 @@ private Object getHtmlFormattedFieldValue(String fieldName, Object fieldValue) {
getHtmlFormattedAndPhoneSforceFieldList();
if (htmlFormattedSforceFieldList == null
|| !htmlFormattedSforceFieldList.contains(fieldName)
|| !getController().getAppConfig().getBoolean(AppConfig.LOAD_PRESERVE_WHITESPACE_IN_RICH_TEXT)) {
|| !getController().getAppConfig().getBoolean(AppConfig.PROP_LOAD_PRESERVE_WHITESPACE_IN_RICH_TEXT)) {
return fieldValue;
}
return convertToHTMLFormatting((String)fieldValue, this.richTextRegex);
Expand Down Expand Up @@ -427,7 +427,7 @@ private Object getPhoneFieldValue(String fieldName, Object fieldValue) {
getHtmlFormattedAndPhoneSforceFieldList();
if (this.phoneSforceFieldList == null
|| !this.phoneSforceFieldList.contains(fieldName)
|| !this.getConfig().getBoolean(AppConfig.FORMAT_PHONE_FIELDS)) {
|| !this.getConfig().getBoolean(AppConfig.PROP_FORMAT_PHONE_FIELDS)) {
return fieldValue;
}
String localeStr = Locale.getDefault().toString();
Expand Down
Loading

0 comments on commit 2532ee1

Please sign in to comment.