use of com.liferay.apio.architect.writer.alias.RepresentorFunction in project com-liferay-apio-architect by liferay.
the class PageWriter method _writeNestedResources.
private <S, U> void _writeNestedResources(RepresentorFunction representorFunction, SingleModel<U> singleModel, JSONObjectBuilder itemJsonObjectBuilder, SingleModel<S> rootSingleModel, FunctionalList<String> embeddedPathElements) {
Optional<Representor<U, ?>> representorOptional = unsafeCast(representorFunction.apply(singleModel.getResourceName()));
representorOptional.ifPresent(_representor -> {
Map<String, Representor<?, ?>> nested = _representor.getNested();
nested.forEach((key, value) -> {
Map<String, Function<U, ?>> nestedFunctions = _representor.getNestedFunctions();
Function<U, ?> nestedMapper = nestedFunctions.get(key);
Object mappedModel = nestedMapper.apply(singleModel.getModel());
FunctionalList<String> embeddedNestedPathElements = new FunctionalList<>(embeddedPathElements, key);
_writeItemEmbeddedModelFields(new SingleModel<>(mappedModel, "", Collections.emptyList()), embeddedNestedPathElements, itemJsonObjectBuilder, __ -> Optional.of(value), rootSingleModel);
});
});
}
use of com.liferay.apio.architect.writer.alias.RepresentorFunction in project com-liferay-apio-architect by liferay.
the class SingleModelWriter method _writeNestedResources.
private <S> void _writeNestedResources(RepresentorFunction representorFunction, SingleModel<S> singleModel, FunctionalList<String> embeddedPathElements) {
Optional<Representor<S, ?>> representorOptional = unsafeCast(representorFunction.apply(singleModel.getResourceName()));
representorOptional.ifPresent(_representor -> {
Map<String, Representor<?, ?>> nested = _representor.getNested();
nested.forEach((key, value) -> {
Map<String, Function<S, ?>> nestedFunctions = _representor.getNestedFunctions();
Function<S, ?> nestedMapper = nestedFunctions.get(key);
Object mappedModel = nestedMapper.apply(singleModel.getModel());
FunctionalList<String> embeddedNestedPathElements = new FunctionalList<>(embeddedPathElements, key);
writeEmbeddedModelFields(new SingleModel<>(mappedModel, "", Collections.emptyList()), embeddedNestedPathElements, __ -> Optional.of(value));
});
});
}
Aggregations