Skip to content

Commit

Permalink
Merge pull request #1336 from ashitsalesforce/master
Browse files Browse the repository at this point in the history
prefix all property names with "PROP_" for code maintainability
  • Loading branch information
ashitsalesforce authored Oct 14, 2024
2 parents e4e4320 + 4a08b1e commit 3304bc6
Show file tree
Hide file tree
Showing 17 changed files with 132 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ protected boolean isRowConversionSuccessful() {
public boolean visit(Row row) throws OperationException, DataAccessObjectException,
ConnectionException {
AppConfig appConfig = controller.getAppConfig();
if (appConfig.getBoolean(AppConfig.PROCESS_BULK_CACHE_DATA_FROM_DAO)
if (appConfig.getBoolean(AppConfig.PROP_PROCESS_BULK_CACHE_DATA_FROM_DAO)
|| (!appConfig.isBulkAPIEnabled() && !appConfig.isBulkV2APIEnabled())) {
// either bulk mode or cache bulk data uploaded from DAO
this.daoRowList.add(row);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ private String generateBatchCSVFilename(String prefix, int batchNum) {
private void createBatch(ByteArrayOutputStream os, int numRecords) throws AsyncApiException {
if (numRecords <= 0) return;
final byte[] request = os.toByteArray();
if (controller.getAppConfig().getBoolean(AppConfig.SAVE_BULK_SERVER_LOAD_AND_RAW_RESULTS_IN_CSV)) {
if (controller.getAppConfig().getBoolean(AppConfig.PROP_SAVE_BULK_SERVER_LOAD_AND_RAW_RESULTS_IN_CSV)) {
this.batchCountForJob++;
writeServerLoadBatchDataToCSV(os);
}
Expand Down Expand Up @@ -449,7 +449,7 @@ private void getResults() throws AsyncApiException, OperationException, DataAcce
return;
}
DataReader dataReader = null;
if (!controller.getAppConfig().getBoolean(AppConfig.PROCESS_BULK_CACHE_DATA_FROM_DAO)) {
if (!controller.getAppConfig().getBoolean(AppConfig.PROP_PROCESS_BULK_CACHE_DATA_FROM_DAO)) {
dataReader = resetDAO();
}
// create a map of batch infos by batch id. Each batchinfo has the final processing state of the batch
Expand Down Expand Up @@ -490,7 +490,7 @@ private void processResults(final DataReader dataReader, final BatchInfo batch,

final int totalRowsInDAOInCurrentBatch = lastDAORowForCurrentBatch - this.firstDAORowForCurrentBatch + 1;
List<Row> rows;
if (controller.getAppConfig().getBoolean(AppConfig.PROCESS_BULK_CACHE_DATA_FROM_DAO)) {
if (controller.getAppConfig().getBoolean(AppConfig.PROP_PROCESS_BULK_CACHE_DATA_FROM_DAO)) {
rows = new ArrayList<Row>();
for (int i=0; i<totalRowsInDAOInCurrentBatch; i++) {
rows.add(i, this.daoRowList.get(i + this.firstDAORowForCurrentBatch));
Expand Down Expand Up @@ -519,7 +519,7 @@ private void processBatchResults(final BatchInfo batch, final String errorMessag
// get the batch csv result stream from sfdc
final CSVReader resultRdr = this.jobUtil.getBatchResults(batch.getId());

if (controller.getAppConfig().getBoolean(AppConfig.SAVE_BULK_SERVER_LOAD_AND_RAW_RESULTS_IN_CSV)) {
if (controller.getAppConfig().getBoolean(AppConfig.PROP_SAVE_BULK_SERVER_LOAD_AND_RAW_RESULTS_IN_CSV)) {
this.batchCountForJob++;
writeRawResultsToCSV(this.jobUtil.getBatchResults(batch.getId()), this.batchCountForJob);
}
Expand Down
93 changes: 57 additions & 36 deletions src/main/java/com/salesforce/dataloader/config/AppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public class AppConfig {
private Properties readOnlyPropertiesFromPropertiesFile = new LinkedProperties();
private final Properties defaultProperties;
private final boolean saveAllProps;
private Map<String,ConfigProperty> configPropsMap = ConfigProperty.getPropertiesMap();
private Map<String,ConfigPropertyMetadata> configPropsMetadataMap = ConfigPropertyMetadata.getPropertiesMap();

private Map<String, String> parameterOverridesMap;

Expand Down Expand Up @@ -429,16 +429,16 @@ public class AppConfig {
public static final String RUN_MODE_INSTALL_VAL = "install";
public static final String RUN_MODE_ENCRYPT_VAL = "encrypt";

public static final String SAVE_BULK_SERVER_LOAD_AND_RAW_RESULTS_IN_CSV = "process.bulk.saveServerLoadAndRawResultsInCSV";
public static final String PROCESS_BULK_CACHE_DATA_FROM_DAO = "process.bulk.cacheDataFromDao";
public static final String READ_ONLY_CONFIG_PROPERTIES = "config.properties.readonly";
public static final String WIZARD_WIDTH = "sfdc.ui.wizard.width";
public static final String WIZARD_HEIGHT = "sfdc.ui.wizard.height";
public static final String WIZARD_X_OFFSET = "sfdc.ui.wizard.xoffset";
public static final String WIZARD_Y_OFFSET = "sfdc.ui.wizard.yoffset";
public static final String ENFORCE_WIZARD_WIDTH_HEIGHT_CONFIG = "sfdc.ui.wizard.enforceWidthHeight";
public static final String WIZARD_CLOSE_ON_FINISH = "sfdc.ui.wizard.closeOnFinish";
public static final String WIZARD_POPULATE_RESULTS_FOLDER_WITH_PREVIOUS_OP_RESULTS_FOLDER = "sfdc.ui.wizard.finishStep.prepopulateWithPreviousOpResultsFolder";
public static final String PROP_SAVE_BULK_SERVER_LOAD_AND_RAW_RESULTS_IN_CSV = "process.bulk.saveServerLoadAndRawResultsInCSV";
public static final String PROP_PROCESS_BULK_CACHE_DATA_FROM_DAO = "process.bulk.cacheDataFromDao";
public static final String PROP_READ_ONLY_CONFIG_PROPERTIES = "config.properties.readonly";
public static final String PROP_WIZARD_WIDTH = "sfdc.ui.wizard.width";
public static final String PROP_WIZARD_HEIGHT = "sfdc.ui.wizard.height";
public static final String PROP_WIZARD_X_OFFSET = "sfdc.ui.wizard.xoffset";
public static final String PROP_WIZARD_Y_OFFSET = "sfdc.ui.wizard.yoffset";
public static final String PROP_ENFORCE_WIZARD_WIDTH_HEIGHT_CONFIG = "sfdc.ui.wizard.enforceWidthHeight";
public static final String PROP_WIZARD_CLOSE_ON_FINISH = "sfdc.ui.wizard.closeOnFinish";
public static final String PROP_WIZARD_POPULATE_RESULTS_FOLDER_WITH_PREVIOUS_OP_RESULTS_FOLDER = "sfdc.ui.wizard.finishStep.prepopulateWithPreviousOpResultsFolder";
public static final String DIALOG_BOUNDS_PREFIX = "sfdc.ui.dialog.";
public static final String DIALOG_WIDTH_SUFFIX = ".width";
public static final String DIALOG_HEIGHT_SUFFIX = ".height";
Expand All @@ -453,7 +453,7 @@ public class AppConfig {
// Following properties are read-only, i.e. they are not overridden during save() to config.properties
// - These properties are not set in Advanced Settings dialog.
// - Make sure to list all sensitive properties such as password because these properties are not saved.
private static final String[] READ_ONLY_PROPERTY_NAMES = {
static final String[] READ_ONLY_PROPERTY_NAMES = {
PROP_PASSWORD,
PROP_IDLOOKUP_FIELD,
PROP_MAPPING_FILE,
Expand All @@ -468,16 +468,16 @@ public class AppConfig {
PROP_DEBUG_MESSAGES_FILE,
PROP_WIRE_OUTPUT,
PROP_PROCESS_THREAD_NAME,
PROCESS_BULK_CACHE_DATA_FROM_DAO,
PROP_PROCESS_BULK_CACHE_DATA_FROM_DAO,
PROP_PROCESS_EXIT_WITH_ERROR_ON_FAILED_ROWS_BATCH_MODE,
SAVE_BULK_SERVER_LOAD_AND_RAW_RESULTS_IN_CSV,
PROP_SAVE_BULK_SERVER_LOAD_AND_RAW_RESULTS_IN_CSV,
PROP_API_VERSION,
PROP_READ_CHARSET,
READ_ONLY_CONFIG_PROPERTIES,
PROP_READ_ONLY_CONFIG_PROPERTIES,
PROP_RICH_TEXT_FIELD_REGEX,
PROP_DAO_READ_PREPROCESSOR_SCRIPT,
PROP_DAO_WRITE_POSTPROCESSOR_SCRIPT,
ENFORCE_WIZARD_WIDTH_HEIGHT_CONFIG,
PROP_ENFORCE_WIZARD_WIDTH_HEIGHT_CONFIG,
PROP_DELETE_WITH_EXTERNALID,
PROP_OAUTH_ACCESSTOKEN,
PROP_OAUTH_REFRESHTOKEN,
Expand All @@ -497,7 +497,7 @@ public class AppConfig {
PROP_USE_SYSTEM_PROPS_FOR_HTTP_CLIENT,
};

private static final String[] ENCRYPTED_PROPERTY_NAMES = {
static final String[] ENCRYPTED_PROPERTY_NAMES = {
PROP_PASSWORD,
PROP_PROXY_PASSWORD,
PROP_OAUTH_ACCESSTOKEN,
Expand Down Expand Up @@ -657,19 +657,19 @@ private void setDefaults(Map<String, String> cliOptionsMap) {
setDefaultValue(PROP_OAUTH_LOGIN_FROM_BROWSER, true);
setDefaultValue(PROP_LOAD_PRESERVE_WHITESPACE_IN_RICH_TEXT, true);
setDefaultValue(AppConfig.CLI_OPTION_RUN_MODE, AppConfig.RUN_MODE_UI_VAL);
setDefaultValue(SAVE_BULK_SERVER_LOAD_AND_RAW_RESULTS_IN_CSV, false);
setDefaultValue(PROCESS_BULK_CACHE_DATA_FROM_DAO, true);
setDefaultValue(PROP_SAVE_BULK_SERVER_LOAD_AND_RAW_RESULTS_IN_CSV, false);
setDefaultValue(PROP_PROCESS_BULK_CACHE_DATA_FROM_DAO, true);
setDefaultValue(PROP_PROCESS_KEEP_ACCOUNT_TEAM, false);
setDefaultValue(WIZARD_WIDTH, DEFAULT_WIZARD_WIDTH);
setDefaultValue(WIZARD_HEIGHT, DEFAULT_WIZARD_HEIGHT);
setDefaultValue(ENFORCE_WIZARD_WIDTH_HEIGHT_CONFIG, true);
setDefaultValue(PROP_WIZARD_WIDTH, DEFAULT_WIZARD_WIDTH);
setDefaultValue(PROP_WIZARD_HEIGHT, DEFAULT_WIZARD_HEIGHT);
setDefaultValue(PROP_ENFORCE_WIZARD_WIDTH_HEIGHT_CONFIG, true);
setDefaultValue(PROP_DAO_READ_PREPROCESSOR_SCRIPT, "");
setDefaultValue(PROP_DAO_WRITE_POSTPROCESSOR_SCRIPT, "");
setDefaultValue(PROP_LIMIT_OUTPUT_TO_QUERY_FIELDS, true);
setDefaultValue(WIZARD_CLOSE_ON_FINISH, true);
setDefaultValue(WIZARD_POPULATE_RESULTS_FOLDER_WITH_PREVIOUS_OP_RESULTS_FOLDER, true);
setDefaultValue(WIZARD_X_OFFSET, DEFAULT_WIZARD_X_OFFSET);
setDefaultValue(WIZARD_Y_OFFSET, DEFAULT_WIZARD_Y_OFFSET);
setDefaultValue(PROP_WIZARD_CLOSE_ON_FINISH, true);
setDefaultValue(PROP_WIZARD_POPULATE_RESULTS_FOLDER_WITH_PREVIOUS_OP_RESULTS_FOLDER, true);
setDefaultValue(PROP_WIZARD_X_OFFSET, DEFAULT_WIZARD_X_OFFSET);
setDefaultValue(PROP_WIZARD_Y_OFFSET, DEFAULT_WIZARD_Y_OFFSET);
setDefaultValue(PROP_CACHE_DESCRIBE_GLOBAL_RESULTS, true);
setDefaultValue(PROP_PROCESS_EXIT_WITH_ERROR_ON_FAILED_ROWS_BATCH_MODE, false);
setDefaultValue(PROP_INCLUDE_RICH_TEXT_FIELD_DATA_IN_QUERY_RESULTS, false);
Expand Down Expand Up @@ -1008,7 +1008,30 @@ private void load(InputStream in) throws ConfigInitializationException, IOExcept

dirty = false;
}


public static boolean isReadOnlyProperty(String propertyName) {
if (propertyName == null) {
return false;
}
for (String roProp : AppConfig.READ_ONLY_PROPERTY_NAMES) {
if (roProp.equals(propertyName)) {
return true;
}
}
return false;
}

public static boolean isEncryptedProperty(String propertyName) {
if (propertyName == null) {
return false;
}
for (String encryptedProp : AppConfig.ENCRYPTED_PROPERTY_NAMES) {
if (encryptedProp.equals(propertyName)) {
return true;
}
}
return false;
}
/**
* Post process parameters. Right now, only decrypts encrypted values in the map
*
Expand Down Expand Up @@ -1194,7 +1217,7 @@ public void putValue(String name, String value) {
*/
public void save() throws IOException, GeneralSecurityException {
if (getString(AppConfig.CLI_OPTION_RUN_MODE).equalsIgnoreCase(AppConfig.RUN_MODE_BATCH_VAL)
|| getBoolean(READ_ONLY_CONFIG_PROPERTIES)) {
|| getBoolean(PROP_READ_ONLY_CONFIG_PROPERTIES)) {
return; // do not save any updates to config.properties file
}
if (filename == null) {
Expand Down Expand Up @@ -1472,15 +1495,13 @@ private <T> void setValue(String name, T value, boolean skipIfAlreadySet) {
}
}

private void setConfigProperty(String propName, String propVal, boolean isDefault) {
ConfigProperty configProp = configPropsMap.get(propName);
if (configProp == null) {
configProp = new ConfigProperty(propName);
configPropsMap.put(propName, configProp);
private void setConfigPropertyMetadata(String propName, String propVal, boolean isDefault) {
ConfigPropertyMetadata configPropMD = configPropsMetadataMap.get(propName);
if (configPropMD == null) {
return; // did not find the property metadata in the registry of properties
}
configProp.setValue(propVal);
if (isDefault) {
configProp.setDefaultValue(propVal);
configPropMD.setDefaultValue(propVal);
}
}

Expand All @@ -1489,7 +1510,7 @@ private void setConfigProperty(String propName, String propVal, boolean isDefaul
* @param newValue
*/
private void setProperty(String name, String newValue, boolean skipIfAlreadySet) {
setConfigProperty(name, newValue, skipIfAlreadySet);
setConfigPropertyMetadata(name, newValue, skipIfAlreadySet);
final String oldValue = getString(name);
if (skipIfAlreadySet && oldValue != null && !oldValue.isBlank()) {
// do not override the old value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,44 @@
*/
package com.salesforce.dataloader.config;

import java.lang.reflect.Field;
import java.util.HashMap;

import com.salesforce.dataloader.ui.Labels;

/*
* Data class capturing information about configuration property (aka Setting).
*/
public class ConfigProperty {
private static final HashMap<String, ConfigProperty> propertiesMap = new HashMap<String, ConfigProperty>();
public class ConfigPropertyMetadata {
private static final HashMap<String, ConfigPropertyMetadata> propertiesMap = new HashMap<String, ConfigPropertyMetadata>();

private final String name;
private String defaultValue = "";
private String value = "";
private boolean readonly;
private boolean encrypted;
private boolean commandLineOption;
private boolean readOnly = false;
private boolean encrypted = false;
private boolean commandLineOption = false;
private final String uiLabelTemplate;
private final String uiTooltipTemplate;

static {
Field[] appConfigFields = AppConfig.class.getDeclaredFields();
for (Field configField : appConfigFields) {
if (configField.getName().startsWith("PROP_")) {
String propName;
try {
propName = configField.get(null).toString();
} catch (SecurityException | IllegalArgumentException | IllegalAccessException e) {
continue;
}
ConfigPropertyMetadata configProp = new ConfigPropertyMetadata(configField.getName());
configProp.setEncrypted(AppConfig.isEncryptedProperty(propName));
configProp.setReadOnly(AppConfig.isReadOnlyProperty(propName));
propertiesMap.put(propName, configProp);
}
}
}

public ConfigProperty(String name) {
public ConfigPropertyMetadata(String name) {
this.name = name;
this.uiLabelTemplate = Labels.getString("AdvancedSettingsDialog.uiLabel." + name);
String tooltipText = null;
Expand Down Expand Up @@ -73,7 +91,7 @@ public ConfigProperty(String name) {
};
}

public static HashMap<String, ConfigProperty> getPropertiesMap() {
public static HashMap<String, ConfigPropertyMetadata> getPropertiesMap() {
return propertiesMap;
}
public String getDefaultValue() {
Expand All @@ -82,17 +100,11 @@ public String getDefaultValue() {
public void setDefaultValue(String defaultValue) {
this.defaultValue = defaultValue;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public boolean isReadonly() {
return readonly;
public boolean isReadOnly() {
return readOnly;
}
public void setReadonly(boolean readonly) {
this.readonly = readonly;
public void setReadOnly(boolean readonly) {
this.readOnly = readonly;
}
public boolean isEncrypted() {
return encrypted;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void resetCurrentRowIndex() {
public Row getCurrentRow() {
AppConfig appConfig = AppConfig.getCurrentConfig();
if (currentRowIndex >= totalRows
|| !appConfig.getBoolean(AppConfig.PROCESS_BULK_CACHE_DATA_FROM_DAO)) {
|| !appConfig.getBoolean(AppConfig.PROP_PROCESS_BULK_CACHE_DATA_FROM_DAO)) {
return null;
}
return rowList.get(currentRowIndex++);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public Row readRow() throws DataAccessObjectException {
return row;
}

if (appConfig.getBoolean(AppConfig.PROCESS_BULK_CACHE_DATA_FROM_DAO)
if (appConfig.getBoolean(AppConfig.PROP_PROCESS_BULK_CACHE_DATA_FROM_DAO)
&& endOfFileReached) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public Row readRow() throws DataAccessObjectException {
currentRowNumber++;
return row;
}
if (appConfig.getBoolean(AppConfig.PROCESS_BULK_CACHE_DATA_FROM_DAO)
if (appConfig.getBoolean(AppConfig.PROP_PROCESS_BULK_CACHE_DATA_FROM_DAO)
&& endOfDBReached) {
return null;
}
Expand Down
Loading

0 comments on commit 3304bc6

Please sign in to comment.