Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Feb 15, 2023
2 parents 75bba84 + 98ca712 commit f33ccf0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,15 @@ public void handleDataRecord(int sequentialNumber, C record, RunningTask workerT
// handle subreport parameters that have asRow=true, we'll create "new virtual rows")
List<SubreportParameterType> paramsAsRow = getSubreports(true);
if (paramsAsRow.isEmpty()) {
processSingleDataRecord(sequentialNumber, record, variables, workerTask, result);
processSingleDataRecord(sequentialNumber, record, variables, paramsAsRow, workerTask, result);
return;
}

boolean rowsCreated = handleSubreportParameters(sequentialNumber, record, paramsAsRow, variables, workerTask, result);
boolean rowsCreated = handleSubreportParameters(
sequentialNumber, record, paramsAsRow, variables, workerTask, result);

if (!rowsCreated) {
processSingleDataRecord(sequentialNumber, record, variables, workerTask, result);
processSingleDataRecord(sequentialNumber, record, variables, paramsAsRow, workerTask, result);
}
}

Expand All @@ -280,7 +281,8 @@ private <T> List<T> tail(List<T> list) {
return new ArrayList<>(list.subList(1, list.size()));
}

private boolean handleSubreportParameters(int sequentialNumber, C record, List<SubreportParameterType> params, VariablesMap variables, RunningTask task, OperationResult result) {
private boolean handleSubreportParameters(int sequentialNumber, C record,
List<SubreportParameterType> params, VariablesMap variables, RunningTask task, OperationResult result) {
SubreportParameterType param = params.stream().findFirst().orElse(null);
if (param == null) {
return false;
Expand All @@ -291,7 +293,7 @@ private boolean handleSubreportParameters(int sequentialNumber, C record, List<S
return false;
}

TypedValue<?> value = map.get(param.getName());
TypedValue<?> value = map.get(param.getName());
if (value == null || value.getValue() == null) {
return false;
}
Expand All @@ -301,9 +303,9 @@ private boolean handleSubreportParameters(int sequentialNumber, C record, List<S
VariablesMap vars = new VariablesMap();
vars.putAll(variables);

List<Object> rows = new ArrayList<>();
List<Object> rows = new ArrayList<>();
if (obj instanceof Collection) {
rows.addAll((Collection<?>) obj);
rows.addAll((Collection<?>) obj);
} else {
rows.add(obj);
}
Expand All @@ -328,7 +330,7 @@ private boolean handleSubreportParameters(int sequentialNumber, C record, List<S

convertAndWriteRow(sequentialNumber, record, vars, task, result);

rowsCreated = rowsCreated | true;
rowsCreated = true;
} else {
rowsCreated = rowsCreated | handleSubreportParameters(sequentialNumber, record, tail(params), vars, task, result);
}
Expand All @@ -352,7 +354,8 @@ private VariablesMap evaluateSimpleSubreportParameters(VariablesMap variables, R
return resultMap;
}

private void convertAndWriteRow(int sequentialNumber, C record, VariablesMap variables, RunningTask workerTask, OperationResult result) {
private void convertAndWriteRow(int sequentialNumber, C record,
VariablesMap variables, RunningTask workerTask, OperationResult result) {
ColumnDataConverter<C> columnDataConverter =
new ColumnDataConverter<>(record, report, variables, reportService, workerTask, result);

Expand All @@ -365,8 +368,16 @@ private void convertAndWriteRow(int sequentialNumber, C record, VariablesMap var
dataWriter.appendDataRow(dataRow);
}

private void processSingleDataRecord(int sequentialNumber, C record, VariablesMap variables, RunningTask workerTask, OperationResult result) {
variables.putAll(this.reportService.evaluateSubreportParameters(report.asPrismObject(), variables, workerTask, result));
/** Used for cases when there are no asRows params, or when no rows are generated by them. */
private void processSingleDataRecord(int sequentialNumber, C record, VariablesMap variables,
List<SubreportParameterType> paramsAsRow, RunningTask workerTask, OperationResult result) {
variables.putAll(evaluateSimpleSubreportParameters(variables, workerTask, result));
for (SubreportParameterType asRowParam : paramsAsRow) {
// We don't want to re-evaluate the sub-reports, but we need some value for each variable.
// Null wrapped in TypedValue is also an alternative, but report scripts would need to check it
// (e.g. use ?.) which currently some test reports do not do - empty collection works fine for them.
variables.put(asRowParam.getName(), new TypedValue<>(List.of(), List.class));
}

convertAndWriteRow(sequentialNumber, record, variables, workerTask, result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
<collection>
<!-- Type is declared in the view element. -->
<filter>
<q:text>. ownedBy (@type = UserType and @path = roleMembershipRef
/*and name = 'user-v1'*/)
<q:text>
. ownedBy (@type = UserType and @path = roleMembershipRef)
</q:text>
</filter>
</collection>
Expand Down Expand Up @@ -78,7 +78,7 @@
<script>
<objectVariableMode>prismReference</objectVariableMode>
<code>
return !data.owner ? 'Unknown owner' : data.owner.name.orig
return data?.owner?.name?.orig ?: 'Unknown owner'
</code>
</script>
</expression>
Expand All @@ -95,7 +95,7 @@
<script>
<objectVariableMode>prismReference</objectVariableMode>
<code>
return input?.object?.name
return input?.object?.name?.orig
</code>
</script>
</expression>
Expand All @@ -114,7 +114,7 @@
<objectVariableMode>prismReference</objectVariableMode>
<code>
//com.evolveum.midpoint.util.DebugUtil.dump(assignmentPaths)
if (!data.assignmentPath) {
if (!data?.assignmentPath) {
return '?'
}

Expand Down Expand Up @@ -142,7 +142,7 @@
<expression>
<script>
<code>
if (!data.assignmentPath) {
if (!data?.assignmentPath) {
return "?"
}

Expand All @@ -168,7 +168,7 @@
<export>
<expression>
<script>
<code>data.assignment?.activation?.effectiveStatus</code>
<code>data?.assignment?.activation?.effectiveStatus</code>
</script>
</expression>
</export>
Expand All @@ -182,7 +182,7 @@
<export>
<expression>
<script>
<code>data.assignment?.activation?.validTo</code>
<code>data?.assignment?.activation?.validTo</code>
</script>
</expression>
</export>
Expand All @@ -196,7 +196,7 @@
<export>
<expression>
<script>
<code>data.createTimestamp</code>
<code>data?.createTimestamp</code>
</script>
</expression>
</export>
Expand Down

0 comments on commit f33ccf0

Please sign in to comment.