/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package aufgabe09.validatoren;

import aufgabe09.entitaeten.Bestellposten;
import aufgabe09.entitaeten.Bestellung;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 *
 * @author x
 */
public class PreiskontrolleValidator implements
        ConstraintValidator<Preiskontrolle, Bestellung> {

  private int grenze;

  public void initialize(Preiskontrolle a) {
    grenze=a.grenze();
  }

  public boolean isValid(Bestellung t, ConstraintValidatorContext cvc) {
   int summe = 0;
   for (Bestellposten bp : t.getPosten())
        summe += bp.getAnzahl() * bp.getProdukt().getVerkaufspreis();
   return summe<=grenze;
  }

}
