Exemplo n.º 1
0
  public static void executeTask() {
    final String ts = new DateTime().toString("yyyy-MM-dd HH:mm:ss");
    final VirtualHost virtualHost = VirtualHost.getVirtualHostForThread();

    List<String> toAddress = new ArrayList<String>();
    Language.setLocale(Language.getDefaultLocale());
    for (Person person : getPeopleToProcess()) {
      Authenticate.authenticate(person.getUsername(), StringUtils.EMPTY, false);
      Map<AcquisitionProcessStateType, MultiCounter<AcquisitionProcessStateType>>
          generateAcquisitionMap = ProcessMapGenerator.generateAcquisitionMap(person, true);
      Map<RefundProcessStateType, MultiCounter<RefundProcessStateType>> generateRefundMap =
          ProcessMapGenerator.generateRefundMap(person, true);

      if (!generateAcquisitionMap.isEmpty() || !generateRefundMap.isEmpty()) {
        toAddress.clear();
        try {
          final String email = person.getEmail();
          if (email != null) {
            final Sender sender = virtualHost.getSystemSender();
            final PersistentGroup group = SingleUserGroup.getOrCreateGroup(person.getUser());
            new Message(
                sender,
                Collections.EMPTY_SET,
                Collections.singleton(group),
                Collections.EMPTY_SET,
                Collections.EMPTY_SET,
                null,
                "Processos Pendentes - Aquisições",
                getBody(generateAcquisitionMap, generateRefundMap, virtualHost),
                null);
          }
        } catch (final Throwable ex) {
          System.out.println("Unable to lookup email address for: " + person.getUsername());
          // skip this person... keep going to next.
        }
      }
    }
  }
 public static boolean isActive() {
   final VirtualHost virtualHost = VirtualHost.getVirtualHostForThread();
   return virtualHost != null && isActive(virtualHost.getHostname());
 }