Skip to content

Commit

Permalink
Fixed bugs according to test case
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentinoAvonEFSA committed Jan 4, 2018
1 parent 8027dab commit 947ac88
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 112 deletions.
11 changes: 11 additions & 0 deletions src/acknowledge/AckLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/app_config/AppPaths.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
9 changes: 6 additions & 3 deletions src/global_utils/Warnings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/report/EFSAReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
59 changes: 41 additions & 18 deletions src/report/Report.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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() {
Expand Down
134 changes: 44 additions & 90 deletions src/report/ReportAckManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()) {

Expand All @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 947ac88

Please sign in to comment.