use of com.evolveum.midpoint.web.page.admin.reports.dto.ReportDto in project midpoint by Evolveum.
the class RunReportPopupPanel method runConfirmPerformed.
// private void addFormUpdatingBehavior(FormComponent parent, String id, final IModel<JasperReportParameterDto> model) {
// Component c = parent.get(id);
// if (c == null) {
// return;
// }
// c.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
// }
private void runConfirmPerformed(AjaxRequestTarget target, IModel<ReportDto> model) {
ReportDto reportDto = model.getObject();
PrismContainerDefinition<ReportParameterType> paramContainerDef = getPrismContext().getSchemaRegistry().findContainerDefinitionByElementName(ReportConstants.REPORT_PARAMS_PROPERTY_NAME);
PrismContainer<ReportParameterType> paramContainer;
try {
paramContainer = paramContainerDef.instantiate();
ReportParameterType reportParam = new ReportParameterType();
PrismContainerValue<ReportParameterType> reportParamValue = reportParam.asPrismContainerValue();
reportParamValue.revive(getPrismContext());
paramContainer.add(reportParamValue);
List<JasperReportParameterDto> params = getParametersView().getModelObject();
for (JasperReportParameterDto paramDto : params) {
if (paramDto.getValue() == null) {
continue;
}
List<JasperReportValueDto> values = paramDto.getValue();
Class<?> paramClass = paramDto.getType();
boolean multivalue = false;
if (List.class.isAssignableFrom(paramClass)) {
paramClass = paramDto.getNestedType();
if (paramClass == null) {
getSession().error("Nested type for list must be defined!");
target.add(getPageBase().getFeedbackPanel());
return;
}
}
QName typeName = getPrismContext().getSchemaRegistry().determineTypeForClass(paramClass);
PrismPropertyDefinitionImpl<?> def = new PrismPropertyDefinitionImpl<>(new QName(ReportConstants.NS_EXTENSION, paramDto.getName()), typeName, getPrismContext());
def.setDynamic(true);
def.setRuntimeSchema(true);
// TODO multivalue is always 'false' here ...
def.setMaxOccurs(multivalue ? -1 : 1);
PrismProperty prop = def.instantiate();
for (JasperReportValueDto paramValue : values) {
Object realValue = paramValue.getValue();
if (realValue == null) {
continue;
}
if (AuditEventType.class.isAssignableFrom(paramClass)) {
paramClass = AuditEventTypeType.class;
realValue = AuditEventType.fromAuditEventType((AuditEventType) realValue);
} else if (AuditEventStage.class.isAssignableFrom(paramClass)) {
paramClass = AuditEventStageType.class;
realValue = AuditEventStage.fromAuditEventStage((AuditEventStage) realValue);
}
prop.addRealValue(realValue);
}
if (!prop.isEmpty()) {
reportParamValue.add(prop);
}
}
} catch (SchemaException | ClassNotFoundException e) {
OperationResult result = new OperationResult("Parameters serialization");
result.recordFatalError("Could not serialize parameters");
getPageBase().showResult(result);
return;
}
runConfirmPerformed(target, reportDto.getObject().asObjectable(), paramContainer);
}
use of com.evolveum.midpoint.web.page.admin.reports.dto.ReportDto in project midpoint by Evolveum.
the class PageReport method loadReport.
private ReportDto loadReport() {
StringValue reportOid = getPageParameters().get(OnePageParameterEncoder.PARAMETER);
Task task = createSimpleTask(OPERATION_LOAD_REPORT);
OperationResult result = task.getResult();
PrismObject<ReportType> prismReport = WebModelServiceUtils.loadObject(ReportType.class, reportOid.toString(), this, task, result);
if (prismReport == null) {
LOGGER.error("Couldn't load report.");
throw new RestartResponseException(PageReports.class);
}
return new ReportDto(prismReport.asObjectable());
// return prismReport;
}
use of com.evolveum.midpoint.web.page.admin.reports.dto.ReportDto in project midpoint by Evolveum.
the class JasperReportConfigurationPanel method addParameterPerformed.
private void addParameterPerformed(AjaxRequestTarget target) {
ReportDto dto = getModel().getObject();
JasperReportParameterDto parameter = new JasperReportParameterDto();
parameter.setEditing(true);
dto.getJasperReportDto().getParameters().add(parameter);
BoxedTablePanel<JasperReportParameterDto> parametersTable = getParametersTable();
adjustParametersTablePage(parametersTable, dto);
target.add(getParametersTable());
}
use of com.evolveum.midpoint.web.page.admin.reports.dto.ReportDto in project midpoint by Evolveum.
the class PageNewReport method importReportFromStreamPerformed.
private void importReportFromStreamPerformed(AjaxRequestTarget target) {
String xml = xmlEditorModel.getObject();
if (StringUtils.isEmpty(xml)) {
error(getString("PageNewReport.message.emptyXml"));
target.add(getFeedbackPanel());
return;
}
OperationResult result = new OperationResult(OPERATION_IMPORT_REPORT_XML);
InputStream stream = null;
try {
setResponsePage(new PageReport(new ReportDto(Base64.encodeBase64(xml.getBytes()))));
} catch (Exception ex) {
result.recordFatalError("Couldn't import object.", ex);
LoggingUtils.logUnexpectedException(LOGGER, "Error occured during xml import", ex);
} finally {
if (stream != null) {
IOUtils.closeQuietly(stream);
}
}
if (result.isSuccess()) {
xmlEditorModel.setObject(null);
}
showResult(result);
target.add(getFeedbackPanel());
}
use of com.evolveum.midpoint.web.page.admin.reports.dto.ReportDto in project midpoint by Evolveum.
the class PageNewReport method importReportFromFilePerformed.
private void importReportFromFilePerformed(AjaxRequestTarget target) {
OperationResult result = new OperationResult(OPERATION_IMPORT_REPORT);
FileUploadField file = (FileUploadField) get(createComponentPath(ID_MAIN_FORM, ID_INPUT, ID_INPUT_FILE, ID_FILE_INPUT));
final FileUpload uploadedFile = file.getFileUpload();
if (uploadedFile == null) {
error(getString("PageNewReport.message.nullFile"));
target.add(getFeedbackPanel());
return;
}
InputStream stream = null;
File newFile = null;
try {
// Create new file
MidPointApplication application = getMidpointApplication();
WebApplicationConfiguration config = application.getWebApplicationConfiguration();
File folder = new File(config.getImportFolder());
if (!folder.exists() || !folder.isDirectory()) {
folder.mkdir();
}
newFile = new File(folder, uploadedFile.getClientFileName());
// Check new file, delete if it already exists
if (newFile.exists()) {
newFile.delete();
}
// Save file
// Task task = createSimpleTask(OPERATION_IMPORT_FILE);
newFile.createNewFile();
uploadedFile.writeTo(newFile);
InputStreamReader reader = new InputStreamReader(new FileInputStream(newFile), "utf-8");
// reader.
stream = new ReaderInputStream(reader, reader.getEncoding());
byte[] reportIn = IOUtils.toByteArray(stream);
setResponsePage(new PageReport(new ReportDto(Base64.encodeBase64(reportIn))));
} catch (Exception ex) {
result.recordFatalError("Couldn't import file.", ex);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't import file", ex);
} finally {
if (stream != null) {
IOUtils.closeQuietly(stream);
}
if (newFile != null) {
FileUtils.deleteQuietly(newFile);
}
}
showResult(result);
target.add(getFeedbackPanel());
}
Aggregations