Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
titleControlLoopInstantiationProvider
linenumberstrue
@Service
public class ControlLoopInstantiationProvider {
    private final ControlLoopProvider controlLoopProvider;
    private final CommissioningProvider commissioningProvider;

    /**
     * Create a instantiation provider.
     *
     * @param databaseProviderParameters the parameters for database access
     */
    public ControlLoopInstantiationProvider(ControlLoopProvider controlLoopProvider,
            CommissioningProvider commissioningProvider) {
        this.controlLoopProvider = controlLoopProvider;
        this.commissioningProvider = commissioningProvider;
    }

    @Transactional
    privatepublic voidInstantiationResponse createControlLoopsOpcreateControlLoops(ControlLoops controlLoops) throws PfModelException {
        for (ControlLoop controlLoop : controlLoops.getControlLoopList()) {
            ControlLoop checkControlLoop = controlLoopProvider.getControlLoop(controlLoop.getKey().asIdentifier());
            if (checkControlLoop != null) {
                throw new PfModelException(Response.Status.BAD_REQUEST,
                        controlLoop.getKey().asIdentifier() + " already defined");
            }
        }
        BeanValidationResult validationResult = validateControlLoops(controlLoops);
        if (!validationResult.isValid()) {
            throw new PfModelException(Response.Status.BAD_REQUEST, validationResult.getResult());
        }
        controlLoopProvider.createControlLoops(controlLoops.getControlLoopList());
    }

    /**
     * Create control loops.
     *
     * @param controlLoops the control loop
     * @return the result of the instantiation operation
     * @throws PfModelException on creation errors
     */
    public InstantiationResponse createControlLoops(ControlLoops controlLoops) throws PfModelException {
        createControlLoopsOp(controlLoops);
        InstantiationResponse response = new InstantiationResponse();
        response.setAffectedControlLoops(controlLoops.getControlLoopList().stream()
                .map(cl -> cl.getKey().asIdentifier()).collect(Collectors.toList()));

        return response;
    }

...