Untitled

 avatar
unknown
plain_text
9 months ago
3.0 kB
3
Indexable
  private void sendNotifyMailUsers(TemplateMail tm, List<TempSM> tempSMs, EmailComunicazioneWrap ecw, List<User> users, List<QueueMetricsPlus> queueMetricsPlus, List<String> emailsTo) {
    
    log.info("[NotificaServiceImpl::sendNotifyMailUsers] BEGIN");

    Map<String, String> assetAddressMap = new HashMap<>();

    users.stream()
    .forEach(u -> u.getApplicationAssetsProducer().forEach(aa -> queueMetricsPlus.stream()
    .filter(qmp -> qmp.getQueue().getApplicationAsset().getId().equals(aa.getId()))
    .forEach(qmp -> {
      if(qmp.getQueue().getAddress().endsWith(".E")) {
        
        assetAddressMap.put(qmp.getQueue().getApplicationAsset().getId() + ".E", qmp.getQueue().getAddress());
      } else {
        assetAddressMap.put(qmp.getQueue().getApplicationAsset().getId(), qmp.getQueue().getAddress());
        
      }
    })));
        
    assetAddressMap.forEach((id, address) -> {
      QueueNotificationMail qnm = new QueueNotificationMail();
      try {
        if (id.endsWith(".E")) {
          id = id.replace(".E", "");
        }
        qnm = queueNotificationMailService.findByIdAddressQueue(id);

        if(qnm == null) {

          Blob blob = convertListToBlob(emailsTo);
          qnm = new QueueNotificationMail(id, address, null, new Date(), 0, true, blob, null);
          
          
          Map<String, SimpleMail> warningDMails = new HashMap<>();
          prepareMapMail(tempSMs, warningDMails);
          
          log.info("EmailComunicazioneWrap notify: {}", ecw);

          try {
            sendMailViaSOAP(ecw);
          } catch (RemoteException e1) {
            log.error("{}", e1);
          } finally {
            queueNotificationMailService.saveQueueNotificationMail(qnm);
          }

        } else {
          Date notify = qnm.getLastNotify();
          
          // se la data della notifica è null oppure la data è inferiore, invio la mail
          
          if (!qnm.isNotify()
          && (notify == null || NotificaServiceUtil.compare(notify, timeMailResend))) {
            
            if (!qnm.listEmailsTo().isEmpty()) {
              qnm.setLastNotify(new Date());     
              
              log.info("queue notification mail {}", qnm);  
              Map<String, SimpleMail> warningDMails = new HashMap<>();
              prepareMapMail(tempSMs, warningDMails);
              
              log.info("EmailComunicazioneWrap notify: {}", ecw);
              try {
                sendMailViaSOAP(ecw);
              } catch (RemoteException e1) {
                log.error("An error occurred while sending mail via SOAP: {}", e1.getMessage());
              } finally {
                queueNotificationMailService.saveQueueNotificationMail(qnm);
              }
            }
          }
        }
        
      } catch (Exception e) {
        log.error(e.getMessage());
      }
      
    });
    log.info("[NotificaServiceImpl::sendNotifyMailUsers] END");
    
  }
Editor is loading...
Leave a Comment