Commit 5c614edc authored by mobreza's avatar mobreza
Browse files

Print upsert errors with WARN and successes with DEBUG

parent 6d3c009a
......@@ -3,4 +3,5 @@
/.idea
*.iml
*/.settings
*/.classpath
\ No newline at end of file
*/.classpath
hs_err_pid*.log
......@@ -11,6 +11,7 @@ import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.log4j.Level;
......@@ -44,12 +45,13 @@ import org.genesys2.client.oauth.OAuthAuthenticationException;
import org.genesys2.client.oauth.PleaseRetryException;
import org.springframework.beans.factory.annotation.Autowired;
import swing2swt.layout.BorderLayout;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import swing2swt.layout.BorderLayout;
public class PushDialog extends Dialog {
private static final Logger _log = Logger.getLogger(PushDialog.class);
protected static final int BATCH_SIZE = 50;
......@@ -71,8 +73,8 @@ public class PushDialog extends Dialog {
protected DataSourceLoader dataSourceLoader;
BlockingQueue<Runnable> linkedBlockingDeque = new LinkedBlockingDeque<Runnable>(4);
private ThreadPoolExecutor executorService = new ThreadPoolExecutor(1, 2, 30, TimeUnit.SECONDS,
linkedBlockingDeque, new ThreadPoolExecutor.CallerRunsPolicy());
private ThreadPoolExecutor executorService = new ThreadPoolExecutor(1, 2, 30, TimeUnit.SECONDS, linkedBlockingDeque,
new ThreadPoolExecutor.CallerRunsPolicy());
protected Object result;
protected Shell shell;
......@@ -183,8 +185,8 @@ public class PushDialog extends Dialog {
tltmPushToGenesys.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (SwtUtil.showYesNoPrompt(getParent(), "Confirmation required", "Push data to Genesys server?\n"
+ settings.getOauthSettings().getServerUrl())) {
if (SwtUtil.showYesNoPrompt(getParent(), "Confirmation required",
"Push data to Genesys server?\n" + settings.getOauthSettings().getServerUrl())) {
_log.info("Upsert confirmed");
doPush(GenesysOp.UPSERT);
} else {
......@@ -199,8 +201,8 @@ public class PushDialog extends Dialog {
tltmRemove.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
if (SwtUtil.showYesNoPrompt(getParent(), "Confirmation required", "Delete data from Genesys server?\n"
+ settings.getOauthSettings().getServerUrl())) {
if (SwtUtil.showYesNoPrompt(getParent(), "Confirmation required",
"Delete data from Genesys server?\n" + settings.getOauthSettings().getServerUrl())) {
_log.info("Delete confirmed");
doPush(GenesysOp.DELETE);
} else {
......@@ -458,10 +460,36 @@ public class PushDialog extends Dialog {
}
}
String serverResponse = null;
if (op == GenesysOp.UPSERT)
genesysClient.updateAccessions(instCode, objectMapper.writeValueAsString(accns));
serverResponse = genesysClient.updateAccessions(instCode,
objectMapper.writeValueAsString(accns));
else if (op == GenesysOp.DELETE)
genesysClient.deleteAccessionsByName(instCode, objectMapper.writeValueAsString(accns));
serverResponse = genesysClient.deleteAccessionsByName(instCode,
objectMapper.writeValueAsString(accns));
if (_log.isDebugEnabled())
_log.debug(serverResponse);
_log.info("Push done.");
try {
JsonNode ri = objectMapper.readTree(serverResponse);
ri.forEach(new Consumer<JsonNode>() {
@Override
public void accept(JsonNode t) {
if (t.has("error") && !t.get("error").isNull()) {
_log.error(t.get("error"));
} else if (t.has("result") && !t.get("result").isNull()) {
_log.debug(t.get("result"));
}
}
});
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (OAuthAuthenticationException e) {
_log.error(e.getMessage(), e);
......@@ -478,6 +506,7 @@ public class PushDialog extends Dialog {
futures.add(future);
instCodeBatch.clear();
}
public void setDataSource(IDataSource dataSource) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment