[New] Allow GenericReport to flatMap a row
This commit is contained in:
parent
4fa3f24701
commit
bef18241ae
|
@ -40,22 +40,22 @@ import li.strolch.utils.iso8601.ISO8601;
|
||||||
*/
|
*/
|
||||||
public class GenericReport extends ReportPolicy {
|
public class GenericReport extends ReportPolicy {
|
||||||
|
|
||||||
private Resource reportRes;
|
protected Resource reportRes;
|
||||||
|
|
||||||
private ParameterBag columnsBag;
|
protected ParameterBag columnsBag;
|
||||||
private List<StringParameter> orderingParams;
|
protected List<StringParameter> orderingParams;
|
||||||
private Map<String, StringParameter> filterCriteriaParams;
|
protected Map<String, StringParameter> filterCriteriaParams;
|
||||||
private boolean descending;
|
protected boolean descending;
|
||||||
private boolean allowMissingColumns;
|
protected boolean allowMissingColumns;
|
||||||
private boolean filterMissingValuesAsTrue;
|
protected boolean filterMissingValuesAsTrue;
|
||||||
private List<String> columnIds;
|
protected List<String> columnIds;
|
||||||
private StringParameter dateRangeSelP;
|
protected StringParameter dateRangeSelP;
|
||||||
|
|
||||||
private DateRange dateRange;
|
protected DateRange dateRange;
|
||||||
private Map<ReportFilterPolicy, TypedTuple<StringParameter, StringParameter>> filtersByPolicy;
|
protected Map<ReportFilterPolicy, TypedTuple<StringParameter, StringParameter>> filtersByPolicy;
|
||||||
private MapOfSets<String, String> filtersById;
|
protected MapOfSets<String, String> filtersById;
|
||||||
|
|
||||||
private long counter;
|
protected long counter;
|
||||||
|
|
||||||
protected JsonObject i18nData;
|
protected JsonObject i18nData;
|
||||||
|
|
||||||
|
@ -287,11 +287,14 @@ public class GenericReport extends ReportPolicy {
|
||||||
|
|
||||||
// query the main objects and return a stream
|
// query the main objects and return a stream
|
||||||
stream = queryRows() //
|
stream = queryRows() //
|
||||||
|
|
||||||
// transform each element into a map of Type,Value pairs
|
// transform each element into a map of Type,Value pairs
|
||||||
.map(this::evaluateRow);
|
.map(this::evaluateRow);
|
||||||
|
|
||||||
stream = handleAdditionalTypes(stream);
|
stream = handleAdditionalTypes(stream);
|
||||||
|
|
||||||
|
stream = flatMap(stream);
|
||||||
|
|
||||||
if (hasFilter())
|
if (hasFilter())
|
||||||
stream = stream.filter(this::filter);
|
stream = stream.filter(this::filter);
|
||||||
|
|
||||||
|
@ -303,6 +306,18 @@ public class GenericReport extends ReportPolicy {
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows sub classes to extend this stream, i.e. flat map an object to extend the stream where necessary
|
||||||
|
*
|
||||||
|
* @param stream
|
||||||
|
* the stream to extend
|
||||||
|
*
|
||||||
|
* @return the stream
|
||||||
|
*/
|
||||||
|
public Stream<Map<String, StrolchRootElement>> flatMap(Stream<Map<String, StrolchRootElement>> stream) {
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles additional joining, so that we can join on arbitrary elements, matching on a {@link StringParameter}
|
* Handles additional joining, so that we can join on arbitrary elements, matching on a {@link StringParameter}
|
||||||
*
|
*
|
||||||
|
@ -347,9 +362,9 @@ public class GenericReport extends ReportPolicy {
|
||||||
if (additionalTypeBag == null)
|
if (additionalTypeBag == null)
|
||||||
return stream;
|
return stream;
|
||||||
|
|
||||||
StringParameter objectTypeP = additionalTypeBag.getParameter(PARAM_OBJECT_TYPE, true);
|
StringParameter objectTypeP = additionalTypeBag.getStringP(PARAM_OBJECT_TYPE);
|
||||||
|
|
||||||
StringParameter joinParamP = additionalTypeBag.getParameter(PARAM_JOIN_PARAM, true);
|
StringParameter joinParamP = additionalTypeBag.getStringP(PARAM_JOIN_PARAM);
|
||||||
String[] locatorParts = joinParamP.getValue().split(Locator.PATH_SEPARATOR);
|
String[] locatorParts = joinParamP.getValue().split(Locator.PATH_SEPARATOR);
|
||||||
if (locatorParts.length != 3)
|
if (locatorParts.length != 3)
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
|
@ -364,7 +379,7 @@ public class GenericReport extends ReportPolicy {
|
||||||
mapOfLists.addElement(joinP.getValue(), e);
|
mapOfLists.addElement(joinP.getValue(), e);
|
||||||
}, MapOfLists::addAll);
|
}, MapOfLists::addAll);
|
||||||
|
|
||||||
StringParameter joinWithP = additionalTypeBag.getParameter(PARAM_JOIN_WITH, true);
|
StringParameter joinWithP = additionalTypeBag.getStringP(PARAM_JOIN_WITH);
|
||||||
return stream.flatMap(row -> {
|
return stream.flatMap(row -> {
|
||||||
|
|
||||||
StrolchRootElement joinElement = row.get(joinWithP.getUom());
|
StrolchRootElement joinElement = row.get(joinWithP.getUom());
|
||||||
|
@ -430,7 +445,8 @@ public class GenericReport extends ReportPolicy {
|
||||||
* @return true if the element is to be kept, false if not
|
* @return true if the element is to be kept, false if not
|
||||||
*/
|
*/
|
||||||
protected boolean filterCriteria(StrolchRootElement element) {
|
protected boolean filterCriteria(StrolchRootElement element) {
|
||||||
return !this.filterCriteriaParams.get(element.getType()).isHidden();
|
StringParameter filterCriteriaP = this.filterCriteriaParams.get(element.getType());
|
||||||
|
return !filterCriteriaP.isHidden();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -755,8 +771,24 @@ public class GenericReport extends ReportPolicy {
|
||||||
* @return the stream of {@link StrolchRootElement StrolchRootElement}
|
* @return the stream of {@link StrolchRootElement StrolchRootElement}
|
||||||
*/
|
*/
|
||||||
protected Stream<? extends StrolchRootElement> queryRows() {
|
protected Stream<? extends StrolchRootElement> queryRows() {
|
||||||
StringParameter objectTypeP = this.reportRes.getParameter(BAG_PARAMETERS, PARAM_OBJECT_TYPE);
|
return getStreamFor(getObjectTypeParam());
|
||||||
return getStreamFor(objectTypeP);
|
}
|
||||||
|
|
||||||
|
protected StringParameter getObjectTypeParam() {
|
||||||
|
return this.reportRes.getStringP(BAG_PARAMETERS, PARAM_OBJECT_TYPE);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getObjectType() {
|
||||||
|
return getObjectTypeParam().getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean hasJoinOnType(String type) {
|
||||||
|
return (this.reportRes.hasParameterBag(BAG_JOINS) //
|
||||||
|
&& this.reportRes.getParameterBag(BAG_JOINS).hasParameter(type)) //
|
||||||
|
|| (this.reportRes.hasParameterBag(BAG_ADDITIONAL_TYPE) //
|
||||||
|
&& this.reportRes.getParameterBag(BAG_ADDITIONAL_TYPE).getString(PARAM_OBJECT_TYPE).equals(type)) //
|
||||||
|
|| (this.reportRes.hasParameterBag(BAG_ADDITIONAL_JOINS) //
|
||||||
|
&& this.reportRes.getParameterBag(BAG_ADDITIONAL_JOINS).hasParameter(type));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Stream<? extends StrolchRootElement> getStreamFor(StringParameter objectTypeP) {
|
private Stream<? extends StrolchRootElement> getStreamFor(StringParameter objectTypeP) {
|
||||||
|
@ -851,22 +883,19 @@ public class GenericReport extends ReportPolicy {
|
||||||
List<Parameter<?>> relationParams = relationsBag.getParametersByInterpretationAndUom(interpretation, joinType)
|
List<Parameter<?>> relationParams = relationsBag.getParametersByInterpretationAndUom(interpretation, joinType)
|
||||||
.stream().filter(p -> p.getValueType() == StrolchValueType.STRING).collect(Collectors.toList());
|
.stream().filter(p -> p.getValueType() == StrolchValueType.STRING).collect(Collectors.toList());
|
||||||
|
|
||||||
if (relationParams.isEmpty()) {
|
if (relationParams.isEmpty())
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"Found no relation parameters with UOM " + joinType + " of type " + StrolchValueType.STRING
|
"Found no relation parameters with UOM " + joinType + " of type " + StrolchValueType.STRING
|
||||||
.getType() + " on dependency " + dependency.getLocator());
|
.getType() + " on dependency " + dependency.getLocator());
|
||||||
}
|
if (relationParams.size() > 1)
|
||||||
if (relationParams.size() > 1) {
|
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"Found multiple possible relation parameters for UOM " + joinType + " on dependency " + dependency
|
"Found multiple possible relation parameters for UOM " + joinType + " on dependency " + dependency
|
||||||
.getLocator());
|
.getLocator());
|
||||||
}
|
|
||||||
|
|
||||||
Parameter<?> relationParam = relationParams.get(0);
|
Parameter<?> relationParam = relationParams.get(0);
|
||||||
StringParameter relationP = (StringParameter) relationParam;
|
StringParameter relationP = (StringParameter) relationParam;
|
||||||
if (relationP.getValue().isEmpty() && optional) {
|
if (relationP.getValue().isEmpty() && optional)
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
|
|
||||||
Locator locator = Locator.valueOf(elementType, joinType, relationP.getValue());
|
Locator locator = Locator.valueOf(elementType, joinType, relationP.getValue());
|
||||||
StrolchRootElement joinElem = tx().findElement(locator, true);
|
StrolchRootElement joinElem = tx().findElement(locator, true);
|
||||||
|
|
Loading…
Reference in New Issue