Skip to content

Commit

Permalink
code refactoring of ProgressAdapter classes
Browse files Browse the repository at this point in the history
- eliminated TestProgressMonitor by switching to NihilistProgressAdapter for relevant tests.
- made SWTProgressAdapter a subclass of NihilistProgressAdapter to leverage common member fields and methods.
  • Loading branch information
ashitsalesforce committed Jan 18, 2024
1 parent 020cb5b commit d9e465b
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 211 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@

package com.salesforce.dataloader.action.progress;

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;

/**
* This class implements the ILoaderProgress but does nothing with
* the callbacks.
Expand All @@ -38,88 +35,102 @@
* @author Lexi Viripaeff
* @since 6.0
*/
public enum NihilistProgressAdapter implements ILoaderProgress {
INSTANCE;

public static NihilistProgressAdapter get() {
return INSTANCE;
}
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

//logger
private final Logger logger = LogManager.getLogger(getClass());
private String message = "";
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class NihilistProgressAdapter implements ILoaderProgress {
private String message;
private boolean success = false;
private int numRowsWithError = 0;
private int numberBatchesTotal = 0;
private final Logger logger = LogManager.getLogger(getClass());
private String taskName;
private int workDone;
private int totalWork;
private final List<String> subTasksInOrder = new ArrayList<String>();

@Override
public void beginTask(String name, int totalWork) {

public NihilistProgressAdapter() {
// no op
}

boolean success = false;
@Override
public void beginTask(String name, int totalWork) {
this.taskName = name;
this.totalWork = totalWork;
}

public void doneError(String msg) {
success = false;
message = msg;
logger.error(msg);
}

@Override
public void doneSuccess(String msg) {
success = true;
message = msg;
logger.info(msg);

}

@Override
public void worked(int worked) {

this.workDone += worked;
}

public void setTaskName(String name) {

this.taskName = name;
}

@Override
public void setSubTask(String name) {
this.subTasksInOrder.add(name);
logger.info(name);
}

public String getTaskName() {
return this.taskName;
}

public int getTotalWork() {
return this.totalWork;
}

public int getNumWorked() {
return this.workDone;
}

public List<String> getSubTasks() {
return Collections.unmodifiableList(this.subTasksInOrder);
}

@Override
public boolean isCanceled() {
return false;
}

private int numberBatchesTotal = 0;
@Override
public void setNumberBatchesTotal(int numberBatchesTotal) {
this.numberBatchesTotal = numberBatchesTotal;
}

@Override
public boolean isSuccess() {
return this.success;
}

@Override
public String getMessage() {
return this.message;
}

@Override
public int getNumberBatchesTotal() {
return this.numberBatchesTotal;
}

@Override
public void setNumberRowsWithError(int rowsWithError) {
this.numRowsWithError = rowsWithError;

}

@Override
public int getNumberRowsWithError() {
return this.numRowsWithError;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,13 @@
/**
* @author Lexi Viripaeff
*/
public class SWTProgressAdapter implements ILoaderProgress {
public class SWTProgressAdapter extends NihilistProgressAdapter {

private IProgressMonitor monitor = null;
private String dispMessage;
private final Controller controller;
private boolean success = false;
private int numRowsWithError = 0;

public SWTProgressAdapter(IProgressMonitor monitor_, Controller controller) {
super();
monitor = monitor_;
this.controller = controller;
}
Expand All @@ -55,36 +53,32 @@ public SWTProgressAdapter(IProgressMonitor monitor_, Controller controller) {
*/
@Override
public void beginTask(String name, int totalWork) {
super.beginTask(name, totalWork);
monitor.beginTask(name, totalWork);
}

public void done() {
monitor.done();
}


/*
* (non-Javadoc)
*
* @see com.sfdc.action.progress.ILoaderProgress#done()
*/
@Override
public void doneSuccess(String message) {
success = true;
super.doneSuccess(message);
monitor.done();
controller.setLastOperationSuccessful(true);
dispMessage = message;
Display.getDefault().syncExec(new Thread() {
@Override
public void run() {

//if extraction pop open an extraction finished dialog
if (controller.getConfig().getOperationInfo().isExtraction()) {
ExtractionFinishDialog dlg = new ExtractionFinishDialog(LoaderWindow.getApp().getShell(), controller);
dlg.setMessage(dispMessage);
dlg.setMessage(getMessage());
dlg.open();
} else {
LoadFinishDialog dlg = new LoadFinishDialog(LoaderWindow.getApp().getShell(), controller);
dlg.setMessage(dispMessage);
dlg.setMessage(getMessage());
dlg.open();
}
}
Expand All @@ -94,33 +88,25 @@ public void run() {

@Override
public void doneError(String message) {
success = false;
super.doneError(message);
monitor.done();
controller.setLastOperationSuccessful(false);
dispMessage = message;
Display.getDefault().syncExec(new Thread() {
@Override
public void run() {
UIUtils.errorMessageBox(LoaderWindow.getApp().getShell(), dispMessage);
UIUtils.errorMessageBox(LoaderWindow.getApp().getShell(), getMessage());
}
});
}

public boolean isSuccess() {
return this.success;
}

public String getMessage() {
return this.dispMessage;
}


/*
* (non-Javadoc)
*
* @see com.sfdc.action.progress.ILoaderProgress#worked(int)
*/
@Override
public void worked(int worked) {
super.worked(worked);
monitor.worked(worked);
}

Expand All @@ -130,6 +116,7 @@ public void worked(int worked) {
* @see com.sfdc.action.progress.ILoaderProgress#setTaskName(java.lang.String)
*/
public void setTaskName(String name) {
super.setTaskName(name);
monitor.setTaskName(name);
}

Expand All @@ -140,6 +127,7 @@ public void setTaskName(String name) {
*/
@Override
public void setSubTask(String name) {
super.setSubTask(name);
monitor.subTask(name);
}

Expand All @@ -152,27 +140,4 @@ public void setSubTask(String name) {
public boolean isCanceled() {
return monitor.isCanceled();
}

private int numberBatchesTotal = 0;
@Override
public void setNumberBatchesTotal(int numberBatchesTotal) {
this.numberBatchesTotal = numberBatchesTotal;
}

@Override
public int getNumberBatchesTotal() {
return this.numberBatchesTotal;
}

@Override
public void setNumberRowsWithError(int rowsWithError) {
this.numRowsWithError = rowsWithError;

}

@Override
public int getNumberRowsWithError() {
return this.numRowsWithError;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ protected ProcessRunner() {

public synchronized void run(ILoaderProgress monitor) throws Exception {
if (monitor == null) {
monitor = NihilistProgressAdapter.get();
monitor = new NihilistProgressAdapter();
}
this.monitor = monitor;
final String oldName = Thread.currentThread().getName();
Expand Down
Loading

0 comments on commit d9e465b

Please sign in to comment.