All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.kenshoo.pl.simulation.internal.ActualResultFetcher Maven / Gradle / Ivy

Go to download

A Java persistence layer based on JOOQ for high performance and business flow support.

There is a newer version: 0.1.121-jooq-3.16.3
Show newest version
package com.kenshoo.pl.simulation.internal;

import com.kenshoo.pl.entity.Entity;
import com.kenshoo.pl.entity.EntityField;
import com.kenshoo.pl.entity.EntityType;
import com.kenshoo.pl.entity.Identifier;
import com.kenshoo.pl.entity.internal.EntitiesFetcher;
import com.kenshoo.pl.simulation.ActualMutatorError;

import java.util.Collection;
import java.util.Map;
import java.util.function.Function;

import static org.jooq.lambda.Seq.seq;


public class ActualResultFetcher> {

    private final EntitiesFetcher fetcher;
    private final Collection> inspectedFields;

    public ActualResultFetcher(EntitiesFetcher fetcher, Collection> inspectedFields) {
        this.fetcher = fetcher;
        this.inspectedFields = inspectedFields;
    }

    public Iterable fetch(
            Collection> allIds,
            Map, ActualMutatorError> errors,
            Function, Entity> originalStates) {

        final var finalStates = fetcher.fetchEntitiesByIds(allIds, inspectedFields);

        return seq(allIds).map(id -> {

            final var originalState = originalStates.apply(id);
            final var finalState = finalStates.get(id);

            if (errors.containsKey(id)) {
                return new ActualError(errors.get(id).getDescription());
            }

            if (originalState == null) {
                return new ActualError("Could not find original state");
            }

            if (finalState == null) {
                return new ActualError("Could not find final state");
            }

            return new ActualSuccess(originalState, finalState);
        });
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy