private void sendRejectedPrognosisResponse(Prognosis prognosis, String errorMessage) {
   PrognosisResponse prognosisResponse =
       createRejectedPrognosisResponse(
           prognosis.getMessageMetadata().getConversationID(),
           prognosis.getMessageMetadata().getSenderDomain(),
           prognosis.getSequence(),
           errorMessage);
   putMessageIntoOutgoingQueue(prognosisResponse);
 }
 /**
  * Sends the prognosis response XML to AGR.
  *
  * @param prognosis
  * @param errorMessage
  */
 public void sendPrognosisResponse(Prognosis prognosis, String errorMessage) {
   PrognosisResponse prognosisResponse =
       createPrognosisResponse(
           prognosis.getCongestionPoint(),
           prognosis.getMessageMetadata().getConversationID(),
           prognosis.getMessageMetadata().getSenderDomain(),
           errorMessage);
   prognosisResponse.setPrognosisSequence(prognosis.getSequence());
   putMessageIntoOutgoingQueue(prognosisResponse);
 }
  /** {@inheritDoc} */
  public void action(Prognosis prognosis, Message savedMessage) throws BusinessException {
    LOGGER.info("Prognosis received");
    String entityAddress = prognosis.getCongestionPoint();
    String errorMessage = null;

    try {
      corePlanboardValidatorService.validatePTUDuration(prognosis.getPTUDuration());
      corePlanboardValidatorService.validateTimezone(prognosis.getTimeZone());
      dsoPlanboardValidatorService.validatePtus(prognosis.getPTU());
      dsoPlanboardValidatorService.validateCongestionPoint(entityAddress);
      dsoPlanboardValidatorService.validateAggregator(
          prognosis.getMessageMetadata().getSenderDomain(), entityAddress, prognosis.getPeriod());
      dsoPlanboardValidatorService.validatePeriod(prognosis.getPeriod());
      dsoPlanboardValidatorService.validatePrognosisSequenceNumber(prognosis);
    } catch (BusinessValidationException e) {
      errorMessage = e.getBusinessError().getError();
      LOGGER.debug(errorMessage, e);
    }

    sendPrognosisResponse(prognosis, errorMessage);
    if (errorMessage != null) {
      return;
    }

    coordinator.invokeWorkflow(prognosis, savedMessage);
  }
  /** {@inheritDoc} */
  public void action(Prognosis aPlan, Message savedMessage) throws BusinessException {
    LOGGER.info(
        "A-Plan received for date {} with {} PTUs", aPlan.getPeriod(), aPlan.getPTU().size());

    String usefIdentifier = aPlan.getMessageMetadata().getSenderDomain();

    // Normalizing PTU list.
    List<PTU> normalizedPtus = PtuListConverter.normalize(aPlan.getPTU());
    aPlan.getPTU().clear();
    aPlan.getPTU().addAll(normalizedPtus);

    try {
      corePlanboardValidatorService.validatePTUDuration(aPlan.getPTUDuration());
      corePlanboardValidatorService.validateTimezone(aPlan.getTimeZone());
      brpPlanboardValidatorService.validatePlanboardHasBeenInitialized(
          aPlan.getPeriod(), aPlan.getPTU());
      brpPlanboardValidatorService.validatePtus(aPlan.getPTU());
      brpPlanboardValidatorService.validatePeriod(aPlan.getPeriod());
      brpPlanboardValidatorService.validateAPlanSequenceNumber(aPlan);
      brpPlanboardValidatorService.validateAPlanConnectionGroup(aPlan.getPeriod(), usefIdentifier);
    } catch (BusinessValidationException e) {
      LOGGER.warn(e.getMessage(), e);
      sendRejectedPrognosisResponse(aPlan, e.getMessage());
      return;
    }

    // Archive previously received A-Plans first.
    corePlanboardBusinessService.archiveAPlans(usefIdentifier, aPlan.getPeriod());

    // Store the received A-Plan in the Planboard. No prognosis response is sent at this moment.
    corePlanboardBusinessService.storePrognosis(
        usefIdentifier,
        aPlan,
        DocumentType.A_PLAN,
        DocumentStatus.RECEIVED,
        usefIdentifier,
        savedMessage,
        false);
    receivedAPlanEventManager.fire(new ReceivedAPlanEvent(aPlan.getPeriod()));
  }