protected boolean validateTemplateFile() { ReportTemplate template = getItem(); if (!Boolean.TRUE.equals(template.getCustom()) && hasTemplateOutput(template.getReportOutputType()) && template.getContent() == null) { StringBuilder notification = new StringBuilder(getMessage("template.uploadTemplate")); if (StringUtils.isEmpty(template.getCode())) { notification.append("\n").append(getMessage("template.codeMsg")); } if (template.getOutputType() == null) { notification.append("\n").append(getMessage("template.outputTypeMsg")); } showNotification(getMessage("validationFail.caption"), notification.toString(), NotificationType.TRAY); return false; } return true; } }
protected boolean validateInputOutputFormats() { ReportTemplate template = getItem().getDefaultTemplate(); if (template != null && !template.isCustom() && template.getReportOutputType() != ReportOutputType.CHART && template.getReportOutputType() != ReportOutputType.TABLE && template.getReportOutputType() != ReportOutputType.PIVOT_TABLE) { String inputType = template.getExt(); if (!ReportPrintHelper.getInputOutputTypesMapping().containsKey(inputType) || !ReportPrintHelper.getInputOutputTypesMapping().get(inputType).contains(template.getReportOutputType())) { showNotification(getMessage("inputOutputTypesError"), NotificationType.TRAY); return false; } } return true; }
protected ReportTemplate createDefaultTemplate(Report report, ReportData reportData) { ReportTemplate reportTemplate = metadata.create(ReportTemplate.class); reportTemplate.setReport(report); reportTemplate.setCode(ReportService.DEFAULT_TEMPLATE_CODE); reportTemplate.setName(reportData.getTemplateFileName()); reportTemplate.setContent(reportData.getTemplateContent()); reportTemplate.setCustom(Boolean.FALSE); Integer outputFileTypeId = reportData.getOutputFileType().getId(); reportTemplate.setReportOutputType(ReportOutputType.fromId(outputFileTypeId)); if (StringUtils.isNotEmpty(reportData.getOutputNamePattern())) { reportTemplate.setOutputNamePattern(reportData.getOutputNamePattern()); } report.setDefaultTemplate(reportTemplate); report.setTemplates(Collections.singletonList(reportTemplate)); return reportTemplate; }
public void setPivotTableDescription(PivotTableDescription description) { if (description != null && getReportOutputType() == ReportOutputType.PIVOT_TABLE) { setContent(PivotTableDescription.toJsonString(description).getBytes(StandardCharsets.UTF_8)); setName(".pivot"); } } }
public boolean supportAlterableForTemplate(ReportTemplate template) { if (BooleanUtils.isTrue(template.getCustom())) { return false; } if (template.getReportOutputType() == ReportOutputType.CHART || template.getReportOutputType() == ReportOutputType.TABLE) { return false; } return BooleanUtils.isTrue(template.getAlterable()); } }
@Override protected void initNewItem(ReportTemplate template) { if (StringUtils.isEmpty(template.getCode())) { Report report = template.getReport(); if (report != null) { if (report.getTemplates() == null || report.getTemplates().isEmpty()) template.setCode(ReportService.DEFAULT_TEMPLATE_CODE); else template.setCode("Template_" + Integer.toString(report.getTemplates().size())); } } }
String fileName = templateUploadField.getFileName(); ReportTemplate reportTemplate = getItem(); reportTemplate.setName(fileName); reportTemplate.setContent(data); } catch (IOException ex) { throw new RuntimeException( String.format("An error occurred while uploading file for template [%s]", getItem().getCode()), ex); byte[] templateFile = reportTemplate.getContent(); if (templateFile != null) { templateUploadField.setContentProvider(() -> new ByteArrayInputStream(templateFile)); FileDescriptor fileDescriptor = metadata.create(FileDescriptor.class); fileDescriptor.setName(reportTemplate.getName()); templateUploadField.setValue(fileDescriptor); boolean updatePermitted = security.isEntityOpPermitted(reportTemplate.getMetaClass(), EntityOp.UPDATE) && security.isEntityAttrUpdatePermitted(reportTemplate.getMetaClass(), "content");
if (frame.isApplicable(reportTemplate.getReportOutputType())) { if (!frame.applyChanges()) { return false; if (!Boolean.TRUE.equals(reportTemplate.getCustom())) { reportTemplate.setCustomDefinition(""); if (reportTemplate.getReportOutputType() == ReportOutputType.TABLE) { reportTemplate.setName(".table"); new byte[0] : templateFileEditor.getValue().getBytes(StandardCharsets.UTF_8); reportTemplate.setContent(bytes);
protected TemplateInfo mapTemplateInfo(ReportTemplate template) { TemplateInfo templateInfo = new TemplateInfo(); templateInfo.code = template.getCode(); templateInfo.outputType = template.getReportOutputType().toString(); return templateInfo; }
final ReportTemplate defaultTemplate = getItem().getDefaultTemplate(); if (defaultTemplate != null) { if (defaultTemplate.getOutputType() != CubaReportOutputType.chart) { File file = fileUpload.getFile(invisibleFileUpload.getFileId()); try { byte[] data = FileUtils.readFileToByteArray(file); defaultTemplate.setContent(data); defaultTemplate.setName(invisibleFileUpload.getFileName()); templatesDs.modifyItem(defaultTemplate); } catch (IOException e) { throw new RuntimeException(String.format( "An error occurred while uploading file for template [%s]", defaultTemplate.getCode()));
@Override public void setItem(ReportTemplate reportTemplate) { super.setItem(reportTemplate); setBands(reportTemplate.getReport().getBands()); if (isApplicable(reportTemplate.getReportOutputType())) { setChartDescription(reportTemplate.getChartDescription()); sortSeriesByOrder(); } }
@Override public void setItem(ReportTemplate reportTemplate) { super.setItem(reportTemplate); setBands(reportTemplate.getReport().getBands()); if (isApplicable(reportTemplate.getReportOutputType())) { if (reportTemplate.getPivotTableDescription() == null) { pivotTableDs.setItem(createDefaultPivotTableDescription()); } else { pivotTableDs.setItem(reportTemplate.getPivotTableDescription()); } } initRendererTypes(); propertyTable.expandAll(); }
protected boolean validateInputOutputFormats() { ReportTemplate reportTemplate = getItem(); String name = reportTemplate.getName(); if (!Boolean.TRUE.equals(reportTemplate.getCustom()) && hasTemplateOutput(reportTemplate.getReportOutputType()) && name != null) { String inputType = name.contains(".") ? name.substring(name.lastIndexOf(".") + 1) : ""; ReportOutputType outputTypeValue = outputType.getValue(); if (!ReportPrintHelper.getInputOutputTypesMapping().containsKey(inputType) || !ReportPrintHelper.getInputOutputTypesMapping().get(inputType).contains(outputTypeValue)) { showNotification(getMessage("inputOutputTypesError"), NotificationType.TRAY); return false; } } return true; }
template.setContent(readBytesFromEntry(archiveReader)); if (StringUtils.isBlank(template.getName())) { template.setName(namePaths[2]);
@Override public void actionPerform(Component component) { ReportTemplate template = (ReportTemplate) target.getSingleSelected(); if (template != null) { ReportTemplate copy = metadata.getTools().copy(template); copy.setId(uuidSource.createUuid()); String copyNamingPattern = getMessage("template.copyNamingPattern"); String copyCode = String.format(copyNamingPattern, StringUtils.isEmpty(copy.getCode()) ? StringUtils.EMPTY : copy.getCode()); //noinspection unchecked List<String> codes = (List<String>) target.getDatasource().getItems().stream() .map(o -> ((ReportTemplate) o).getCode()) .filter(o -> !StringUtils.isEmpty((String) o)) .collect(Collectors.toList()); if (codes.contains(copyCode)) { String code = copyCode; int i = 0; while ((codes.contains(code))) { i += 1; code = copyCode + " " + i; } copyCode = code; } copy.setCode(copyCode); //noinspection unchecked target.getDatasource().addItem(copy); } }
@Override public void ready() { super.ready(); ReportTemplate reportTemplate = getItem(); initTemplateEditor(reportTemplate); getDescriptionEditFrames().forEach(controller -> controller.setItem(reportTemplate)); setupVisibility(reportTemplate.getCustom(), reportTemplate.getReportOutputType()); }
@Override public com.haulmont.yarg.structure.ReportOutputType getOutputType() { return getReportOutputType() != null ? getReportOutputType().getOutputType() : null; }
if (template.isCustom()) { CustomFormatter customFormatter = new CustomFormatter(report, template); template.setCustomReport(customFormatter); ReportOutputType resultOutputType = (outputType != null) ? outputType.getOutputType() : template.getOutputType();
ReportTemplate existingTemplate = em.find(ReportTemplate.class, loadedTemplate.getId()); if (existingTemplate != null) { loadedTemplate.setVersion(existingTemplate.getVersion()); if (PersistenceHelper.isNew(loadedTemplate)) { PersistenceHelper.makeDetached(loadedTemplate); loadedTemplate.setVersion(0); loadedTemplate.setReport(report); savedTemplates.add(em.merge(loadedTemplate)); if (savedTemplate.equals(defaultTemplate)) { defaultTemplate = savedTemplate; break;
@Override public InputStream getDocumentContent() { if (getContent() == null) { return null; } return new ByteArrayInputStream(getContent()); }