Search in sources :

Example 1 with RepresentorFunction

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);
        });
    });
}
Also used : ResourceNameFunction(com.liferay.apio.architect.writer.alias.ResourceNameFunction) SingleModelFunction(com.liferay.apio.architect.writer.alias.SingleModelFunction) Function(java.util.function.Function) PathFunction(com.liferay.apio.architect.writer.alias.PathFunction) RepresentorFunction(com.liferay.apio.architect.writer.alias.RepresentorFunction) FunctionalList(com.liferay.apio.architect.list.FunctionalList) JsonObject(com.google.gson.JsonObject) Representor(com.liferay.apio.architect.representor.Representor)

Example 2 with RepresentorFunction

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));
        });
    });
}
Also used : ResourceNameFunction(com.liferay.apio.architect.writer.alias.ResourceNameFunction) RepresentorFunction(com.liferay.apio.architect.writer.alias.RepresentorFunction) SingleModelFunction(com.liferay.apio.architect.writer.alias.SingleModelFunction) Function(java.util.function.Function) PathFunction(com.liferay.apio.architect.writer.alias.PathFunction) FunctionalList(com.liferay.apio.architect.list.FunctionalList) JsonObject(com.google.gson.JsonObject) Representor(com.liferay.apio.architect.representor.Representor)

Aggregations

JsonObject (com.google.gson.JsonObject)2 FunctionalList (com.liferay.apio.architect.list.FunctionalList)2 Representor (com.liferay.apio.architect.representor.Representor)2 PathFunction (com.liferay.apio.architect.writer.alias.PathFunction)2 RepresentorFunction (com.liferay.apio.architect.writer.alias.RepresentorFunction)2 ResourceNameFunction (com.liferay.apio.architect.writer.alias.ResourceNameFunction)2 SingleModelFunction (com.liferay.apio.architect.writer.alias.SingleModelFunction)2 Function (java.util.function.Function)2