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;
}
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();
}
}
}
}
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);
}
}
}
}
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));
}
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();
}
Aggregations