Search in sources :

Example 1 with ReportInputParameter

use of io.jmix.reports.entity.ReportInputParameter in project jmix by jmix-framework.

the class ParametersFragment method createEntityParameters.

private List<ReportInputParameter> createEntityParameters() {
    List<ReportInputParameter> newParameters = new ArrayList<>();
    Map<String, List<String>> entityWithProperties = new HashMap<>();
    extractEntityParams(entityWithProperties, emailTemplateDc.getItem().getHtml());
    extractEntityParams(entityWithProperties, emailTemplateDc.getItem().getSubject());
    for (Map.Entry<String, List<String>> entry : entityWithProperties.entrySet()) {
        String entityAlias = entry.getKey();
        ReportInputParameter parameter = getParameter(entityAlias);
        if (parameter == null) {
            parameter = initNewParameter(entityAlias);
            parameter.setType(ParameterType.ENTITY);
            newParameters.add(parameter);
        }
        if (parameter.getEntityMetaClass() == null) {
            List<String> fields = entry.getValue();
            MetaClass metaClass = findMetaClassForFields(fields);
            if (metaClass != null) {
                parameter.setEntityMetaClass(metaClass.getName());
            }
        }
        if (parameter.getParameterClass() == null) {
            parameter.setParameterClass(parameterClassResolver.resolveClass(parameter));
        }
    }
    return newParameters;
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) HashMap(java.util.HashMap) ReportInputParameter(io.jmix.reports.entity.ReportInputParameter) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with ReportInputParameter

use of io.jmix.reports.entity.ReportInputParameter in project jmix by jmix-framework.

the class ParametersFragment method inputParametersTableMoveDown.

@Subscribe("inputParametersTable.down")
protected void inputParametersTableMoveDown(Action.ActionPerformedEvent event) {
    ReportInputParameter parameter = (ReportInputParameter) inputParametersTable.getSingleSelected();
    if (parameter != null) {
        List<ReportInputParameter> inputParameters = reportDc.getItem().getInputParameters();
        int index = parameter.getPosition();
        if (index < parametersDc.getItems().size() - 1) {
            ReportInputParameter nextParameter = null;
            for (ReportInputParameter inputParameter : inputParameters) {
                if (inputParameter.getPosition() == index + 1) {
                    nextParameter = inputParameter;
                    break;
                }
            }
            if (nextParameter != null) {
                parameter.setPosition(nextParameter.getPosition());
                nextParameter.setPosition(index);
                sortParametersByPosition();
            }
        }
    }
}
Also used : ReportInputParameter(io.jmix.reports.entity.ReportInputParameter)

Example 3 with ReportInputParameter

use of io.jmix.reports.entity.ReportInputParameter in project jmix by jmix-framework.

the class EmailTemplateSendScreen method setParameter.

public void setParameter(String alias, Object value) {
    List<TemplateReport> templateReports = new ArrayList<>();
    if (emailTemplate.getEmailBodyReport() != null) {
        templateReports.add(emailTemplate.getEmailBodyReport());
    }
    templateReports.addAll(emailTemplate.getAttachedTemplateReports());
    for (TemplateReport templateReport : templateReports) {
        ReportInputParameter inputParameter = templateReport.getReport().getInputParameters().stream().filter(e -> alias.equals(e.getAlias())).findFirst().orElse(null);
        if (inputParameter != null) {
            ParameterValue parameterValue = templateReport.getParameterValues().stream().filter(pv -> pv.getAlias().equals(alias)).findFirst().orElse(null);
            if (parameterValue == null) {
                parameterValue = metadata.create(ParameterValue.class);
                parameterValue.setAlias(alias);
                parameterValue.setParameterType(inputParameter.getType());
                parameterValue.setTemplateReport(templateReport);
                templateReport.getParameterValues().add(parameterValue);
            }
            Class parameterClass = classResolver.resolveClass(inputParameter);
            if (!ParameterType.ENTITY_LIST.equals(inputParameter.getType())) {
                String stringValue = objectToStringConverter.convertToString(parameterClass, value);
                parameterValue.setDefaultValue(stringValue);
            }
        }
    }
}
Also used : ParameterValue(io.jmix.emailtemplates.entity.ParameterValue) ArrayList(java.util.ArrayList) ReportInputParameter(io.jmix.reports.entity.ReportInputParameter) TemplateReport(io.jmix.emailtemplates.entity.TemplateReport)

Example 4 with ReportInputParameter

use of io.jmix.reports.entity.ReportInputParameter in project jmix by jmix-framework.

the class ParameterEditor method initTransformations.

protected void initTransformations() {
    ReportInputParameter parameter = getEditedEntity();
    isPredefinedTransformationField.setValue(parameter.getPredefinedTransformation() != null);
    enableControlsByTransformationType(parameter.getPredefinedTransformation() != null);
    isPredefinedTransformationField.addValueChangeListener(e -> {
        boolean hasPredefinedTransformation = e.getValue() != null && e.getValue();
        enableControlsByTransformationType(hasPredefinedTransformation);
        if (hasPredefinedTransformation) {
            parameter.setTransformationScript(null);
        } else {
            parameter.setPredefinedTransformation(null);
        }
    });
    isPredefinedTransformationField.setEditable(secureOperations.isEntityUpdatePermitted(metadata.getClass(ReportInputParameter.class), policyStore));
}
Also used : ReportInputParameter(io.jmix.reports.entity.ReportInputParameter)

Example 5 with ReportInputParameter

use of io.jmix.reports.entity.ReportInputParameter in project jmix by jmix-framework.

the class ParameterEditor method onParameterDcItemChange.

@Subscribe(id = "parameterDc", target = Target.DATA_CONTAINER)
protected void onParameterDcItemChange(InstanceContainer.ItemChangeEvent<ReportInputParameter> event) {
    ReportInputParameter reportInputParameter = event.getItem();
    ReportInputParameter newParameter = metadata.create(reportInputParameter.getClass());
    metadataTools.copy(reportInputParameter, newParameter);
    newParameter.setId((UUID) Id.of(reportInputParameter).getValue());
    if (newParameter.getParameterClass() == null) {
        newParameter.setParameterClass(parameterClassResolver.resolveClass(newParameter));
    }
    enableControlsByParamType(newParameter.getType());
    initScreensLookup();
    initTransformations();
}
Also used : ReportInputParameter(io.jmix.reports.entity.ReportInputParameter)

Aggregations

ReportInputParameter (io.jmix.reports.entity.ReportInputParameter)22 MetaClass (io.jmix.core.metamodel.model.MetaClass)3 ReportWithParams (io.jmix.emailtemplates.dto.ReportWithParams)3 TemplateReport (io.jmix.emailtemplates.entity.TemplateReport)3 Report (io.jmix.reports.entity.Report)3 ParameterValue (io.jmix.emailtemplates.entity.ParameterValue)2 ReportParameterTypeChangedException (io.jmix.emailtemplates.exception.ReportParameterTypeChangedException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ReportParameter (com.haulmont.yarg.structure.ReportParameter)1 ReportWithParamField (io.jmix.emailtemplatesui.dto.ReportWithParamField)1 ParameterPrototype (io.jmix.reports.app.ParameterPrototype)1 ParameterType (io.jmix.reports.entity.ParameterType)1 FluentUiReportRunner (io.jmix.reportsui.runner.FluentUiReportRunner)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1