Skip to content

Commit

Permalink
minor reports improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Feb 24, 2014
1 parent f96bc19 commit 4351980
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 62 deletions.
Expand Up @@ -23,6 +23,7 @@
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.prism.query.RefFilter;
import com.evolveum.midpoint.prism.query.SubstringFilter;
import com.evolveum.midpoint.report.api.ReportManager;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
Expand Down Expand Up @@ -598,37 +599,30 @@ private ObjectQuery createQuery(){
return query;
}

private InputStream createReport(){
private InputStream createReport() {
OperationResult result = new OperationResult(OPERATION_DOWNLOAD_REPORT);
ReportManager reportManager = getReportManager();

InputStream reportStream;

if(currentReport != null){

try{
reportStream = getReportManager().getReportOutputData(currentReport.getOid(), result);

if(reportStream == null){
throw new FileNotFoundException();
if (currentReport == null) {
return null;
}

} else{
result.recordSuccess();
return reportStream;
}
InputStream input = null;
try {
input = reportManager.getReportOutputData(currentReport.getOid(), result);
} catch (Exception e) {
error(getString("pageCreatedReports.message.downloadError") + " " + e.getMessage());
LoggingUtils.logException(LOGGER, "Couldn't download report.", e);
LOGGER.trace(result.debugDump());
} finally {
result.computeStatusIfUnknown();
}

} catch (FileNotFoundException fe){
result.recordFatalError(getString("pageCreatedReports.message.fileNotFound"));
LoggingUtils.logException(LOGGER, "Couldn't download report, file does not exist.", fe);
LOGGER.trace(result.debugDump());
showResult(result);
} catch (Exception e){
error(getString("pageCreatedReports.message.downloadError") + " " + e.getMessage());
LoggingUtils.logException(LOGGER, "Couldn't download report.", e);
LOGGER.trace(result.debugDump());
}
if (WebMiscUtil.showResultInPage(result)) {
showResultInSession(result);
}

return null;
return input;
}

private void fileTypeFilterPerformed(AjaxRequestTarget target){
Expand Down
Expand Up @@ -298,33 +298,6 @@ private void configurePerformed(AjaxRequestTarget target, ReportType report){
setResponsePage(PageReport.class, params);
}

private QName getObjectClass(String resourceOid) {
if (StringUtils.isEmpty(resourceOid)) {
getSession().error(getString("PageReports.message.resourceNotDefined"));
throw new RestartResponseException(PageReports.class);
}

OperationResult result = new OperationResult(OPERATION_LOAD_RESOURCE);
try {
Task task = createSimpleTask(OPERATION_LOAD_RESOURCE);
PrismObject<ResourceType> resource = getModelService().getObject(ResourceType.class,
resourceOid, null, task, result);
RefinedResourceSchema refinedSchema = RefinedResourceSchema.getRefinedSchema(resource,
LayerType.PRESENTATION, getPrismContext());

RefinedObjectClassDefinition def = refinedSchema.getDefaultRefinedDefinition(ShadowKindType.ACCOUNT);
return def.getTypeName();
} catch (Exception ex) {
result.recordFatalError("Couldn't get default object class qname for resource oid '"
+ resourceOid + "'.", ex);
showResultInSession(result);

LoggingUtils.logException(LOGGER, "Couldn't get default object class qname for resource oid {}",
ex, resourceOid);
throw new RestartResponseException(PageReports.class);
}
}

private ObjectDataProvider getDataProvider(){
DataTable table = getReportTable().getDataTable();
return (ObjectDataProvider) table.getDataProvider();
Expand Down Expand Up @@ -353,7 +326,7 @@ private ObjectQuery createQuery(){
Boolean parent = !dto.isParent();
ObjectQuery query = new ObjectQuery();

if(!StringUtils.isEmpty(text)){
if(StringUtils.isNotEmpty(text)){
PolyStringNormalizer normalizer = getPrismContext().getDefaultPolyStringNormalizer();
String normalizedText = normalizer.normalize(text);

Expand Down Expand Up @@ -382,7 +355,6 @@ private ObjectQuery createQuery(){
return query;
}


private void clearSearchPerformed(AjaxRequestTarget target){
searchModel.setObject(new ReportSearchDto());

Expand All @@ -397,5 +369,5 @@ private void clearSearchPerformed(AjaxRequestTarget target){

target.add(get(ID_SEARCH_FORM));
target.add(panel);
};
}
}
Expand Up @@ -32,6 +32,8 @@
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.xml.JRXmlLoader;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.w3c.dom.Node;
Expand Down Expand Up @@ -361,22 +363,32 @@ private void deleteReportOutput(ReportOutputType reportOutput, OperationResult p

@Override
public InputStream getReportOutputData(String reportOutputOid, OperationResult parentResult) {

Task task = taskManager.createTaskInstance(REPORT_OUTPUT_DATA);

OperationResult result = parentResult.createSubresult(REPORT_OUTPUT_DATA);
InputStream reportData = null;
result.addParam("oid", reportOutputOid);

InputStream reportData = null;
try {
ReportOutputType reportOutput = modelService.getObject(ReportOutputType.class, reportOutputOid, null, task, result).asObjectable();
reportData = new FileInputStream(reportOutput.getFilePath());
ReportOutputType reportOutput = modelService.getObject(ReportOutputType.class, reportOutputOid, null,
task, result).asObjectable();

String filePath = reportOutput.getFilePath();
if (StringUtils.isEmpty(filePath)) {
parentResult.recordFatalError("Report output file path is not defined.");
return null;
}
File file = new File(filePath);
reportData = FileUtils.openInputStream(file);

LOGGER.trace("Report Data : {} ", reportData.toString());
result.recordSuccessIfUnknown();
} catch (Exception e) {
LOGGER.trace("Cannot read the report data : {}", e.getMessage());
result.recordFatalError("Cannot read the report data.", e);
LOGGER.trace("Cannot read the report data : {}", e.getMessage());
reportData = null;
} finally {
result.computeStatusIfUnknown();
}

return reportData;
}
}

0 comments on commit 4351980

Please sign in to comment.