Skip to content

Commit

Permalink
fixing MID-3340 and MID-3917
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed Jun 15, 2017
1 parent 3fc5436 commit afd360b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 12 deletions.
Expand Up @@ -557,12 +557,16 @@ private void downloadPerformed(AjaxRequestTarget target, ReportOutputType report
ajaxDownloadBehavior.initiate(target);
}

private String getReportFileName(){
private String getReportFileName() {
return getReportFileName(currentReport);
}

public static String getReportFileName(ReportOutputType currentReport){
try {
OperationResult result = new OperationResult(OPERATION_GET_REPORT_FILENAME);
ReportOutputType reportOutput = WebModelServiceUtils.loadObject(ReportOutputType.class, currentReport.getOid(), getPageBase(),
null, result).asObjectable();
String fileName = reportOutput.getFilePath();
// ReportOutputType reportOutput = WebModelServiceUtils.loadObject(ReportOutputType.class, currentReport.getOid(), getPageBase(),
// null, result).asObjectable();
String fileName = currentReport.getFilePath();
if (fileName.contains("/")) {
fileName = fileName.substring(fileName.lastIndexOf("/") + 1);
}
Expand Down
Expand Up @@ -39,6 +39,8 @@
*/
public class ReportCreateHandlerPanel extends DefaultHandlerPanel<ReportCreateHandlerDto> {

private static final long serialVersionUID = 1L;

private static final String ID_DOWNLOAD_CONTAINER = "downloadContainer";
private static final String ID_DOWNLOAD = "download";
private static final String ID_REPORT_PARAMETERS_CONTAINER = "reportParametersContainer";
Expand All @@ -52,22 +54,27 @@ public ReportCreateHandlerPanel(String id, IModel<ReportCreateHandlerDto> model,
}

private void initLayout(final PageTaskEdit parentPage) {

final ReportOutputType reportObject = getReportOutput(parentPage);

final AjaxDownloadBehaviorFromStream ajaxDownloadBehavior = new AjaxDownloadBehaviorFromStream() {
private static final long serialVersionUID = 1L;

@Override
protected InputStream initStream() {
String outputOid = getModelObject().getReportOutputOid();
if (outputOid == null) {
return null;
}
Task task = parentPage.createSimpleTask(OPERATION_LOAD_REPORT_OUTPUT);
PrismObject<ReportOutputType> reportObject = WebModelServiceUtils.loadObject(ReportOutputType.class, outputOid, parentPage, task, task.getResult());

if (reportObject != null) {
return PageCreatedReports.createReport(reportObject.asObjectable(), this, parentPage);
return PageCreatedReports.createReport(reportObject, this, parentPage);
} else {
return null;
}
}


@Override
public String getFileName() {
return PageCreatedReports.getReportFileName(reportObject);
}
};
parentPage.getForm().add(ajaxDownloadBehavior);

Expand All @@ -79,18 +86,40 @@ protected InputStream initStream() {

WebMarkupContainer downloadContainer = new WebMarkupContainer(ID_DOWNLOAD_CONTAINER);
AjaxButton download = new AjaxButton(ID_DOWNLOAD) {

private static final long serialVersionUID = 1L;

@Override
public void onClick(AjaxRequestTarget target) {
ajaxDownloadBehavior.initiate(target);
}
};
downloadContainer.add(download);
downloadContainer.add(new VisibleEnableBehaviour() {

private static final long serialVersionUID = 1L;

@Override
public boolean isVisible() {
return getModelObject().getReportOutputOid() != null;
return getModelObject().getReportOutputOid() != null && reportObject != null;
}
});
add(downloadContainer);
}

private ReportOutputType getReportOutput(PageTaskEdit parentPage) {
String outputOid = getModelObject().getReportOutputOid();

if (outputOid == null) {
return null;
}
Task task = parentPage.createSimpleTask(OPERATION_LOAD_REPORT_OUTPUT);
PrismObject<ReportOutputType> reportOutput = WebModelServiceUtils.loadObject(ReportOutputType.class, outputOid, parentPage, task, task.getResult());

if (reportOutput == null) {
return null;
}
return reportOutput.asObjectable();
}

}

0 comments on commit afd360b

Please sign in to comment.