diff --git a/src/acknowledge/AckLog.java b/src/acknowledge/AckLog.java index 30e55f0..1ce4da1 100644 --- a/src/acknowledge/AckLog.java +++ b/src/acknowledge/AckLog.java @@ -33,6 +33,17 @@ public InputStream getRawLog() { return rawLog; } + /** + * Get the data collection used for this message + * @return + */ + public String getDCCode() { + + String code = getFirstNodeText("dcCode"); + + return code; + } + /** * Get the message val res code * @return diff --git a/src/app_config/AppPaths.java b/src/app_config/AppPaths.java index b920038..2b928b1 100644 --- a/src/app_config/AppPaths.java +++ b/src/app_config/AppPaths.java @@ -42,6 +42,7 @@ public class AppPaths { public static final String REPORT_MESSAGE_ID = "reportMessageId"; public static final String REPORT_DATASET_ID = "reportDatasetId"; public static final String REPORT_STATUS = "reportStatus"; + public static final String REPORT_PREVIOUS_STATUS = "reportPreviousStatus"; public static final String REPORT_VERSION = "reportVersion"; public static final String REPORT_VERSION_REGEX = "(\\.\\d{2})?"; // either .01, .02 or .10, .50 (always two digits) } diff --git a/src/global_utils/Warnings.java b/src/global_utils/Warnings.java index c30beb2..5f74533 100644 --- a/src/global_utils/Warnings.java +++ b/src/global_utils/Warnings.java @@ -4,6 +4,7 @@ import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; +import acknowledge.AckLog; import acknowledge.OpResError; import app_config.PropertiesReader; import i18n_messages.Messages; @@ -48,20 +49,22 @@ public static String getStackTrace(Exception e) { return trace; } - public static String[] getAckOperationWarning(OpResError error) { + public static String[] getAckOperationWarning(AckLog log) { + OpResError error = log.getOpResError(); + String title = Messages.get("error.title"); String message = null; switch(error) { case NOT_EXISTING_DC: message = Messages.get("dc.not.valid", - PropertiesReader.getDataCollectionCode(), + log.getDCCode(), PropertiesReader.getSupportEmail()); break; case USER_NOT_AUTHORIZED: message = Messages.get("account.unauthorized", - PropertiesReader.getDataCollectionCode(), + log.getDCCode(), PropertiesReader.getSupportEmail()); break; default: diff --git a/src/report/EFSAReport.java b/src/report/EFSAReport.java index 5701b28..80e881f 100644 --- a/src/report/EFSAReport.java +++ b/src/report/EFSAReport.java @@ -94,7 +94,7 @@ public void reject() throws IOException, * @return * @throws MySOAPException */ - public DatasetStatus updateStatusWithAck(Ack ack) throws MySOAPException; + public DatasetStatus updateStatusWithAck(Ack ack); /** * Get all the datasets related to this report diff --git a/src/report/Report.java b/src/report/Report.java index 31ac9ed..faf0f15 100644 --- a/src/report/Report.java +++ b/src/report/Report.java @@ -332,26 +332,35 @@ public Ack getAck() throws MySOAPException { return ack; } - public DatasetStatus updateStatusWithAck(Ack ack) throws MySOAPException { - - //Ack ack = this.getAck(); + public DatasetStatus updateStatusWithAck(Ack ack) { // if we have something in the ack - if (ack.isReady() && ack.getLog().isOk()) { - - // save id - String datasetId = ack.getLog().getDatasetId(); - this.setDatasetId(datasetId); - - // save status - DatasetStatus status = ack.getLog().getDatasetStatus(); - this.setStatus(status); + if (ack.isReady()) { - // permanently save data - this.update(); - - System.out.println("Ack successful for message id " + this.getMessageId() + ". Retrieved datasetId=" - + datasetId + " with status=" + this.getStatus()); + if (ack.getLog().isOk()) { + + // save id + String datasetId = ack.getLog().getDatasetId(); + this.setDatasetId(datasetId); + + // save status + DatasetStatus status = ack.getLog().getDatasetStatus(); + this.setStatus(status); + + // permanently save data + this.update(); + + System.out.println("Ack successful for message id " + this.getMessageId() + ". Retrieved datasetId=" + + datasetId + " with status=" + this.getStatus()); + } + else { + + // Reset the status with the previous if possible + if(this.getPreviousStatus() != null) { + this.setStatus(this.getPreviousStatus()); + this.update(); + } + } } return this.getStatus(); @@ -403,11 +412,25 @@ public DatasetStatus getStatus() { } public void setStatus(String status) { + this.put(AppPaths.REPORT_PREVIOUS_STATUS, this.getStatus().getLabel()); this.put(AppPaths.REPORT_STATUS, status); } + /** + * Get the previous status of the dataset + * @return + */ + public DatasetStatus getPreviousStatus() { + String status = getCode(AppPaths.REPORT_PREVIOUS_STATUS); + + if (status.isEmpty()) + return null; + + return DatasetStatus.fromString(status); + } + public void setStatus(DatasetStatus status) { - this.put(AppPaths.REPORT_STATUS, status.getStatus()); + this.setStatus(status.getStatus()); } public String getYear() { diff --git a/src/report/ReportAckManager.java b/src/report/ReportAckManager.java index bb0294a..131bce1 100644 --- a/src/report/ReportAckManager.java +++ b/src/report/ReportAckManager.java @@ -52,11 +52,25 @@ public void refreshStatus(Listener listener) { // else if local status UPLOADED, SUBMISSION_SENT, REJECTION_SENT - // get the ack of the dataset - Ack ack = this.getAck(true, listener); + // if no connection return + Ack ack = null; + try { + shell.setCursor(shell.getDisplay().getSystemCursor(SWT.CURSOR_WAIT)); + ack = report.getAck(); + shell.setCursor(shell.getDisplay().getSystemCursor(SWT.CURSOR_ARROW)); + } catch (MySOAPException e) { + e.printStackTrace(); + shell.setCursor(shell.getDisplay().getSystemCursor(SWT.CURSOR_ARROW)); + Warnings.showSOAPWarning(shell, e); + return; + } - if (ack == null) // error occurred + // if no ack return + if (ack == null) { + String message = Messages.get("ack.not.available"); + Warnings.warnUser(shell, Messages.get("error.title"), message); return; + } // if ack is ready then check if the report status // is the same as the one in the get dataset list @@ -66,7 +80,14 @@ public void refreshStatus(Listener listener) { // if TRXOK if (log.isOk()) { - + + // update the report status if required + report.updateStatusWithAck(ack); + + // update the ui accordingly + if (listener != null) + listener.handleEvent(null); + // if no dataset retrieved for the current report if (!log.getDatasetStatus().existsInDCF()) { @@ -90,7 +111,7 @@ public void refreshStatus(Listener listener) { System.err.println(log.getOpResError()); System.err.println(log.getOpResLog()); - String[] warning = Warnings.getAckOperationWarning(log.getOpResError()); + String[] warning = Warnings.getAckOperationWarning(log); Warnings.warnUser(shell, warning[0], warning[1]); } else { @@ -125,10 +146,25 @@ public void displayAck() { return; } - Ack ack = this.getAck(false, null); - - if (ack == null || ack.getLog() == null) + // if no connection return + Ack ack = null; + try { + shell.setCursor(shell.getDisplay().getSystemCursor(SWT.CURSOR_WAIT)); + ack = report.getAck(); + shell.setCursor(shell.getDisplay().getSystemCursor(SWT.CURSOR_ARROW)); + } catch (MySOAPException e) { + e.printStackTrace(); + shell.setCursor(shell.getDisplay().getSystemCursor(SWT.CURSOR_ARROW)); + Warnings.showSOAPWarning(shell, e); return; + } + + // if no ack return + if (ack == null) { + String message = Messages.get("ack.not.available"); + Warnings.warnUser(shell, Messages.get("error.title"), message); + return; + } // get the raw log to send the .xml to the browser InputStream rawLog = ack.getLog().getRawLog(); @@ -156,88 +192,6 @@ public void displayAck() { viewer.open(targetFile); } - /** - * Get an acknowledge of the report - * @param shell - * @param report - * @return - */ - public Ack getAck(boolean updateReportStatus, Listener updateListener) { - - shell.setCursor(shell.getDisplay().getSystemCursor(SWT.CURSOR_WAIT)); - - boolean errorOccurred = false; - String title = Messages.get("error.title"); - String message = null; - int style = SWT.ERROR; - - Ack ack = null; - - try { - - ack = report.getAck(); - - if (ack == null) { - message = Messages.get("ack.not.available"); - errorOccurred = true; - } - else { - - if (ack.getLog() != null) { - - AckLog log = ack.getLog(); - - if (!log.isOk()) { - // errors - if (log.hasErrors()) { - - System.err.println(log.getOpResError()); - System.err.println(log.getOpResLog()); - - String[] warning = Warnings.getAckOperationWarning(log.getOpResError()); - title = warning[0]; - message = warning[1]; - errorOccurred = true; - } - else { - // not reachable - System.err.println("Wrong ack structure. The log is TRXKO but no errors found!"); - errorOccurred = true; - } - } - } - } - - // update the report status if required - if(!errorOccurred && updateReportStatus) { - report.updateStatusWithAck(ack); - } - - // update the ui accordingly - if (!errorOccurred && updateListener != null) - updateListener.handleEvent(null); - - } catch (MySOAPException e) { - e.printStackTrace(); - String[] warning = Warnings.getSOAPWarning(e); - title = warning[0]; - message = warning[1]; - style = SWT.ERROR; - } - finally { - shell.setCursor(shell.getDisplay().getSystemCursor(SWT.CURSOR_ARROW)); - } - - // if a message needs to be shown - if (message != null) { - Warnings.warnUser(shell, title, message, style); - return null; - } - - return ack; - } - - /** * Update the report status with the dataset contained in the DCF * @param shell