コード例 #1
0
 /** DELETE /purchasedRiskItems/:id -> delete the "id" purchasedRiskItem. */
 @RequestMapping(
     value = "/purchasedRiskItems/{id}",
     method = RequestMethod.DELETE,
     produces = MediaType.APPLICATION_JSON_VALUE)
 public ResponseEntity<Void> deletePurchasedRiskItem(@PathVariable Long id) {
   log.debug("REST request to delete PurchasedRiskItem : {}", id);
   purchasedRiskItemRepository.delete(id);
   return ResponseEntity.ok()
       .headers(HeaderUtil.createEntityDeletionAlert("purchasedRiskItem", id.toString()))
       .build();
 }
コード例 #2
0
 /** DELETE /customAdmissionDetailss/:id -> delete the "id" customAdmissionDetails. */
 @RequestMapping(
     value = "/customAdmissionDetailss/{id}",
     method = RequestMethod.DELETE,
     produces = MediaType.APPLICATION_JSON_VALUE)
 @Timed
 public ResponseEntity<Void> deleteCustomAdmissionDetails(@PathVariable Long id) {
   log.debug("REST request to delete CustomAdmissionDetails : {}", id);
   customAdmissionDetailsRepository.delete(id);
   return ResponseEntity.ok()
       .headers(HeaderUtil.createEntityDeletionAlert("customAdmissionDetails", id.toString()))
       .build();
 }
コード例 #3
0
 /** DELETE /organizers/:id -> delete the "id" organizer. */
 @RequestMapping(
     value = "/organizers/{id}",
     method = RequestMethod.DELETE,
     produces = MediaType.APPLICATION_JSON_VALUE)
 @Timed
 public ResponseEntity<Void> deleteOrganizer(@PathVariable Long id) {
   log.debug("REST request to delete Organizer : {}", id);
   organizerService.delete(id);
   return ResponseEntity.ok()
       .headers(HeaderUtil.createEntityDeletionAlert("organizer", id.toString()))
       .build();
 }
コード例 #4
0
 /** DELETE /evolutionPrescriptions/:id -> delete the "id" evolutionPrescription. */
 @RequestMapping(
     value = "/evolutionPrescriptions/{id}",
     method = RequestMethod.DELETE,
     produces = MediaType.APPLICATION_JSON_VALUE)
 @Timed
 public ResponseEntity<Void> delete(@PathVariable Long id) {
   log.debug("REST request to delete EvolutionPrescription : {}", id);
   evolutionPrescriptionRepository.delete(id);
   return ResponseEntity.ok()
       .headers(HeaderUtil.createEntityDeletionAlert("evolutionPrescription", id.toString()))
       .build();
 }
コード例 #5
0
 @RequestMapping(
     value = "/{id}",
     method = RequestMethod.DELETE,
     produces = MediaType.APPLICATION_JSON_VALUE)
 public ResponseEntity<Void> deleteTask(@PathVariable Long id) {
   Task task = taskService.findById(id);
   if (task == null) {
     LOGGER.warn("task id = '" + id + "' is not found");
     return ResponseEntity.badRequest()
         .headers(
             HeaderUtil.createFailureAlert("task-management", "tasknotfound", "Task not found"))
         .body(null);
   } else {
     taskService.delete(task);
     LOGGER.info("task id = '" + id + "' has been deleted");
     return ResponseEntity.ok()
         .headers(HeaderUtil.createAlert("task-management.deleted", id.toString()))
         .build();
   }
 }
コード例 #6
0
ファイル: EntradaController.java プロジェクト: Emmy02/mateo
  @RequestMapping
  public String lista(
      HttpServletRequest request,
      HttpServletResponse response,
      @RequestParam(required = false) String filtro,
      @RequestParam(required = false) Long pagina,
      @RequestParam(required = false) String tipo,
      @RequestParam(required = false) String correo,
      @RequestParam(required = false) String order,
      @RequestParam(required = false) String sort,
      Usuario usuario,
      Errors errors,
      Model modelo) {
    log.debug("Mostrando lista de tipos de entradas");
    Map<String, Object> params = new HashMap<>();
    params.put("almacen", request.getSession().getAttribute("almacenId"));
    if (StringUtils.isNotBlank(filtro)) {
      params.put("filtro", filtro);
    }
    if (pagina != null) {
      params.put("pagina", pagina);
      modelo.addAttribute("pagina", pagina);
    } else {
      pagina = 1L;
      modelo.addAttribute("pagina", pagina);
    }
    if (StringUtils.isNotBlank(order)) {
      params.put("order", order);
      params.put("sort", sort);
    }

    if (StringUtils.isNotBlank(tipo)) {
      params.put("reporte", true);
      params = entradaDao.lista(params);
      try {
        generaReporte(tipo, (List<Entrada>) params.get("entradas"), response);
        return null;
      } catch (JRException | IOException e) {
        log.error("No se pudo generar el reporte", e);
        params.remove("reporte");
        errors.reject("error.generar.reporte");
      }
    }

    if (StringUtils.isNotBlank(correo)) {
      params.put("reporte", true);
      params = entradaDao.lista(params);

      params.remove("reporte");
      try {
        enviaCorreo(correo, (List<Entrada>) params.get("entradas"), request);
        modelo.addAttribute("message", "lista.enviada.message");
        modelo.addAttribute(
            "messageAttrs",
            new String[] {
              messageSource.getMessage("entrada.lista.label", null, request.getLocale()),
              ambiente.obtieneUsuario().getUsername()
            });
      } catch (JRException | MessagingException e) {
        log.error("No se pudo enviar el reporte por correo", e);
      }
    }
    params = entradaDao.lista(params);
    modelo.addAttribute("entradas", params.get("entradas"));

    // inicia paginado
    Long cantidad = (Long) params.get("cantidad");
    Integer max = (Integer) params.get("max");
    Long cantidadDePaginas = cantidad / max;
    List<Long> paginas = new ArrayList<>();
    long i = 1;
    do {
      paginas.add(i);
    } while (i++ < cantidadDePaginas);
    List<Entrada> entradas = (List<Entrada>) params.get("entradas");
    Long primero = ((pagina - 1) * max) + 1;
    Long ultimo = primero + (entradas.size() - 1);
    String[] paginacion = new String[] {primero.toString(), ultimo.toString(), cantidad.toString()};
    modelo.addAttribute("paginacion", paginacion);
    modelo.addAttribute("paginas", paginas);
    // termina paginado

    return "inventario/entrada/lista";
  }
コード例 #7
0
  /** POST /purchaseOrders -> Create a new purchaseOrder. */
  @RequestMapping(
      value = "/purchaseOrders",
      method = RequestMethod.POST,
      produces = MediaType.APPLICATION_JSON_VALUE)
  @Timed
  public ResponseEntity<?> createPurchaseOrder(@RequestBody List<PurchaseOrder> purchaseOrders)
      throws URISyntaxException, JsonProcessingException {

    log.debug("REST request to save PurchaseOrder : {}", purchaseOrders);
    if (purchaseOrders.size() == 0) {
      return ResponseEntity.badRequest()
          .headers(HeaderUtil.createFailureAlert("purchaseOrder", "noitems", "No items selected"))
          .body("{\"error\":\"NoItems\"}");
    }
    // if (purchaseOrder.getId() != null) {
    //
    // }
    User loggedUser = userRepository.findOneByLogin(SecurityUtils.getCurrentUserLogin()).get();
    List<PurchaseOrder> initializedOrders = new ArrayList<PurchaseOrder>();
    List<PurchaseOrder> result = new ArrayList<PurchaseOrder>();
    String concatId = "";

    Iterator<PurchaseOrder> it = purchaseOrders.iterator();
    while (it.hasNext()) {
      PurchaseOrder order = it.next();
      order.setState(OrderStatus.Initial);

      order.setCreationDate(ZonedDateTime.now());

      ArtWorkPiece work = artWorkPieceRepository.findOne(order.getArtWorkPiece().getId());
      if (work.getCommercialState() != CommercialState.ForSale
          || work.getApprovalState() != ApprovalState.Approved) {
        loggedUser = userRepository.findOneByLogin(SecurityUtils.getCurrentUserLogin()).get();
        ObjectMapper mapper = new ObjectMapper();
        Set<WorkPiece> cart = loggedUser.getShoppingCart();
        String cartJSON = mapper.writeValueAsString(cart);
        return ResponseEntity.badRequest()
            .headers(
                HeaderUtil.createFailureAlert(
                    "purchaseOrder",
                    "WorkNotForSale",
                    "An artwork not for sale is trying to be selled"))
            .body("{\"error\":\"WorkNotForSale\",\"cart\":" + cartJSON + "}");
      }

      User artist = userRepository.findOneByLogin(work.getProfile().getUser().getLogin()).get();
      User client = loggedUser;
      order.setArtWorkPiece(work);
      order.setArtist(artist);
      order.setClient(client);

      Address origin;

      if (order.getArtist().getAddresses().size() > 0) {
        origin = order.getArtist().getAddresses().stream().findFirst().get();
      } else {
        loggedUser = userRepository.findOneByLogin(SecurityUtils.getCurrentUserLogin()).get();
        return ResponseEntity.badRequest()
            .headers(
                HeaderUtil.createFailureAlert(
                    "purchaseOrder", "ArtistAddressNotFound", "The artist has no address."))
            .body("{\"error\":\"ArtistAddressNotFound\"}");
      }

      Address destination = order.getDestination();
      Address billing = order.getBilling();
      origin.setId(null);
      destination.setId(null);
      billing.setId(null);
      origin = addressRepository.save(origin);
      destination = addressRepository.save(destination);
      billing = addressRepository.save(billing);
      order.setAddress(origin);
      order.setDestination(destination);
      order.setBilling(billing);

      BigDecimal price = new BigDecimal(work.getPrice());
      Long random = System.currentTimeMillis();

      BigDecimal shippingCost =
          rateWebServiceClient.send(
              random.toString(),
              origin.getCountry().getCountryCode(),
              origin.getZipPostalCode(),
              destination.getCountry().getCountryCode(),
              destination.getZipPostalCode(),
              work.getHeight().toString(),
              work.getWidth().toString(),
              (work.getDepth() != null ? work.getDepth().toString() : "1"),
              work.getPrice().toString());
      work.setShippingCost(shippingCost);
      order.setShippingCosts(shippingCost);
      BigDecimal total = price.add(shippingCost);
      order.setTotal(total);

      initializedOrders.add(order);
    }

    Iterator<PurchaseOrder> itInitialized = initializedOrders.iterator();
    ArrayList<String> createdIds = new ArrayList<>();
    while (itInitialized.hasNext()) {
      PurchaseOrder order = itInitialized.next();
      PurchaseOrder saved = purchaseOrderRepository.save(order);
      result.add(saved);
      createdIds.add(saved.getId().toString());
      concatId += "_" + saved.getId().toString();

      ArtWorkPiece artwork = order.getArtWorkPiece();
      loggedUser.getShoppingCart().remove(artwork);
      artwork.setCommercialState(CommercialState.Sold);
      artWorkPieceRepository.save(artwork);
    }

    // loggedUser.setShoppingCart(null);
    userRepository.save(loggedUser);

    String location = payPalResource.checkout(createdIds);
    ResponseEntity error = checkErrors(location);
    if (error != null) {
      return error;
    }

    return ResponseEntity.created(new URI("/api/purchaseOrders/" + concatId))
        .headers(HeaderUtil.createEntityCreationAlert("purchaseOrder", concatId))
        .body("{\"location\":\"" + location + "\"}");
  }