private void sendMailIfChangeIsInTransit(PurchaseOrder orderOriginal, PurchaseOrder result) {
   if (orderOriginal.getState() == OrderStatus.Confirmed
       && result.getState() == OrderStatus.InProgress) {
     mailService.sentArt(orderOriginal.getClient());
   }
   if (orderOriginal.getState() == OrderStatus.InProgress
       && result.getState() == OrderStatus.Delivered) {
     mailService.deliveredArt(
         orderOriginal.getArtist(), orderOriginal.getArtWorkPiece().getTitle());
   }
 }
  /** PUT /purchaseOrders -> Updates an existing purchaseOrder. */
  @RequestMapping(
      value = "/purchaseOrders",
      method = RequestMethod.PUT,
      produces = MediaType.APPLICATION_JSON_VALUE)
  @Timed
  public ResponseEntity<List<PurchaseOrder>> updatePurchaseOrder(
      @RequestBody PurchaseOrder purchaseOrder) throws URISyntaxException {
    log.debug("REST request to update PurchaseOrder : {}", purchaseOrder);
    if (purchaseOrder.getId() == null) {
      // return createPurchaseOrder(purchaseOrders);
    }
    PurchaseOrder orderOriginal = purchaseOrderRepository.findOne(purchaseOrder.getId());
    orderOriginal.setFollowUpId(purchaseOrder.getFollowUpId());
    orderOriginal.setState(purchaseOrder.getState());
    orderOriginal.setNotes(purchaseOrder.getNotes());
    PurchaseOrder result = purchaseOrderRepository.save(orderOriginal);
    sendMailIfChangeIsInTransit(orderOriginal, result);

    return ResponseEntity.ok()
        .headers(
            HeaderUtil.createEntityUpdateAlert("purchaseOrder", purchaseOrder.getId().toString()))
        .body(null);
  }