Exemplo n.º 1
1
 /**
  * 保存内容管理
  *
  * @param content
  * @return
  */
 @RequestMapping(method = RequestMethod.POST)
 public ResponseEntity<Void> saveContent(Content content) {
   try {
     contentService.save(content);
     return ResponseEntity.status(HttpStatus.CREATED).build();
   } catch (Exception e) {
     e.printStackTrace();
     return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
   }
 }
Exemplo n.º 2
1
 @RequestMapping(
     value = {"/ws/1.0/detail/{requestId}"},
     method = RequestMethod.GET,
     produces = "application/json")
 public ResponseEntity<ReportTask> detail(@PathVariable("requestId") String requestId) {
   ReportTask task = reportService.detail(requestId);
   if (task == null) { // başlamamış
     logManager.info("output :YOK !!! " + requestId);
     return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
   }
   return ResponseEntity.status(HttpStatus.OK).body(task);
 }
Exemplo n.º 3
1
 @RequestMapping(
     value = {"/ws/1.0/cancel/{requestId}"},
     method = RequestMethod.GET,
     produces = "application/json")
 public ResponseEntity<ReportTask> cancel(@PathVariable("requestId") String requestId) {
   try {
     reportService.cancel(requestId);
     return ResponseEntity.status(HttpStatus.OK).body(null);
   } catch (NoSuchElementException e) {
     logManager.info("rapor :YOK !!! " + requestId);
     return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
   }
 }
  @ApiOperation("Return nautical warnings of given status.")
  @RequestMapping(
      method = RequestMethod.GET,
      path = "/nautical-warnings/{status}",
      produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
  @ResponseBody
  public ResponseEntity<?> nauticalWarnings(
      @ApiParam(value = "Status", required = true, allowableValues = "DRAFT,PUBLISHED,ARCHIVED")
          @PathVariable
          final String status) {
    final Status s = Status.valueOf(status.toUpperCase());
    final String url = String.format("%s?layer=%s", pookiUrl, s.layer);

    ResponseEntity<byte[]> response = template.getForEntity(url, byte[].class);

    if (RestUtil.isError(response.getStatusCode())) {
      response = template.getForEntity(url, byte[].class);
    }

    // Pooki unexpectedly returns body in GZip format, try to unzip it
    // If that fails, expect body to be "plain"
    byte[] body;
    try {
      body = decompress(response.getBody());
    } catch (final IOException e) {
      body = response.getBody();
    }

    if (RestUtil.isError(response.getStatusCode())) {
      return ResponseEntity.status(response.getStatusCode()).body(body);
    }

    return ResponseEntity.ok().body(body);
  }
Exemplo n.º 5
1
 @RequestMapping(
     value = {"/ws/1.0/error/{requestId}"},
     method = RequestMethod.GET,
     produces = "text/plain")
 public ResponseEntity<String> error(@PathVariable("requestId") String requestId)
     throws IOException {
   return ResponseEntity.status(HttpStatus.OK).body(reportService.error(requestId));
 }
Exemplo n.º 6
0
  /**
   * 修改
   *
   * @param content
   * @return
   */
  @RequestMapping(value = "edit", method = RequestMethod.POST)
  public ResponseEntity<Void> updateContentByContentId(Content content) {

    try {
      contentService.updateByPrimaryKeySelective(content);
      return ResponseEntity.status(HttpStatus.CREATED).build();
    } catch (Exception e) {
      e.printStackTrace();
      return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }
  }
 @RequestMapping(path = "/get/{cardId}", method = GET, produces = APPLICATION_JSON_VALUE)
 @ResponseStatus(OK)
 public ResponseEntity findAvailable(@PathVariable long cardId) {
   Optional<DiscountCard> dc = service.getCard(cardId);
   if (!dc.isPresent()) {
     return ResponseEntity.status(NOT_FOUND).build();
   }
   return ResponseEntity.ok(dc.get());
 }
 @RequestMapping(path = "/get/by/number", method = GET, produces = APPLICATION_JSON_VALUE)
 @JsonView(DiscountCardView.BasicLevel.class)
 public ResponseEntity getByCardNumber(@RequestParam(required = true) long number) {
   Optional<DiscountCard> discountCards = service.searchByCardNumber(number);
   if (discountCards.isPresent()) {
     return ResponseEntity.ok(discountCards.get());
   }
   return ResponseEntity.status(NOT_FOUND).build();
 }
Exemplo n.º 9
0
  @RequestMapping(value = "/api/authenticate", method = POST)
  public ResponseEntity<AuthResponse> doAuth(@RequestBody @Valid AuthRequest request)
      throws IOException {
    User user = new User();
    user.setEmail(request.getEmail());

    Token token = tokenService.allocateToken(objectMapper.writeValueAsString(user));
    return ResponseEntity.status(HttpStatus.OK).body(new AuthResponse(token.getKey()));
  }
Exemplo n.º 10
0
 @RequestMapping(path = "/get/by/tags", method = GET, produces = APPLICATION_JSON_VALUE)
 @JsonView(DiscountCardView.BasicLevel.class)
 public ResponseEntity getByTags(@RequestParam(required = true) Set<String> tags) {
   Optional<List<DiscountCard>> discountCards = service.searchByTags(tags);
   if (discountCards.isPresent()) {
     return ResponseEntity.ok(discountCards.get());
   }
   return ResponseEntity.status(NOT_FOUND).build();
 }
Exemplo n.º 11
0
 @RequestMapping(
     value = {"/ws/1.0/request"},
     method = RequestMethod.POST,
     produces = "application/json",
     consumes = "application/json")
 @SuppressWarnings("ThrowableResultIgnored")
 public ResponseEntity<ReportResponse> request(@RequestBody(required = true) ReportRequest req) {
   ReportTask res = reportService.request(req);
   return ResponseEntity.status(res.getStatus().getHttpStatus()).body(res.getResponse());
 }
 @RequestMapping(value = "/upload", method = RequestMethod.POST)
 public ResponseEntity<?> handleProfilePhoto(
     @RequestParam("file") MultipartFile file, HttpServletRequest request) {
   try {
     fileService.save(file, request);
   } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   return ResponseEntity.status(HttpStatus.OK).body(null);
 }
 @RequestMapping(value = "/create", method = RequestMethod.POST)
 public ResponseEntity<String> createHomework(HttpServletRequest request) {
   User currentTeacher =
       (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
   if (homeworkService.saveHomework(request, currentTeacher.getId())) {
     return ResponseEntity.ok("Домашняя работа была добавлена");
   } else {
     return ResponseEntity.status(HttpStatus.BAD_REQUEST)
         .body("Проверьте правильность заполнения полей");
   }
 }
 private ResponseEntity handleError(HttpServletRequest request, Exception ex, String value) {
   Map<String, String> rtnMap = Maps.newHashMap();
   rtnMap.put("error", value);
   rtnMap.put("exception", ex.getClass().getName());
   rtnMap.put("message", ex.getMessage());
   if (ex.getCause() != null) {
     rtnMap.put("cause", ex.getCause().toString());
   }
   rtnMap.put("path", request.getServletPath());
   rtnMap.put("status", "500");
   return ResponseEntity.status(500).body(rtnMap);
 }
Exemplo n.º 15
0
 @RequestMapping(
     value = {"/ws/1.0/output/{requestId}"},
     method = RequestMethod.GET)
 public ResponseEntity<byte[]> output(@PathVariable("requestId") String requestId)
     throws IOException {
   try {
     byte[] output = reportService.output(requestId);
     ReportTask task = reportService.detail(requestId);
     logManager.info("output :" + requestId);
     return ResponseEntity.status(HttpStatus.OK)
         .contentType(ReportOutputFormat.valueOf(task.getRequest().getExtension()).getMediaType())
         .lastModified(task.getEnded())
         .header(
             "Content-Disposition",
             "inline; filename=" + requestId + "." + task.getRequest().getExtension())
         .body(output);
   } catch (NoSuchElementException e) {
     logManager.info("output :YOK !!! " + requestId);
     return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
   }
 }
 @GetMapping(value = "/byFirstNameLastName", produces = Datatables.MEDIA_TYPE)
 @ResponseBody
 public ResponseEntity<DatatablesData<Customer>> findByFirstNameLastName(
     CustomerSearchForm formBean,
     GlobalSearch search,
     DatatablesPageable pageable,
     @RequestParam(Datatables.PARAMETER_DRAW) Integer draw) {
   Page<Customer> customers = customerService.findByFirstNameLastName(formBean, search, pageable);
   long allAvailableCustomers = customerService.countByFirstNameLastName(formBean);
   DatatablesData<Customer> datatablesData =
       new DatatablesData<Customer>(customers, allAvailableCustomers, draw);
   return ResponseEntity.status(HttpStatus.FOUND).body(datatablesData);
 }
Exemplo n.º 17
0
  @RequestMapping(path = "/get/by/name", method = GET, produces = APPLICATION_JSON_VALUE)
  @JsonView(DiscountCardView.BasicLevel.class)
  public ResponseEntity getByName(
      @RequestParam(required = true, value = "company_name") String companyName) {
    List<DiscountCard> discountCards =
        SearchEngine.search(
            service.findAll(), companyName, service.searchByCompanyName(companyName));

    if (discountCards.size() > 0) {
      return ResponseEntity.ok(discountCards);
    }
    return ResponseEntity.status(NOT_FOUND).build();
  }
Exemplo n.º 18
0
  /**
   * 分页查询全部内容管理信息 当前子节点
   *
   * @param categoryId
   * @param page
   * @param rows
   * @return
   */
  @RequestMapping(method = RequestMethod.GET)
  public ResponseEntity<EasyUIResult> queryContentList(
      @RequestParam(value = "categoryId") Long categoryId,
      @RequestParam(value = "page", defaultValue = "1") Integer page,
      @RequestParam(value = "rows", defaultValue = "20") Integer rows) {

    try {
      EasyUIResult easyUIResult = this.contentService.queryContentList(categoryId, page, rows);
      return ResponseEntity.ok(easyUIResult);
    } catch (Exception e) {
      e.printStackTrace();
      return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }
  }
Exemplo n.º 19
0
  @PreAuthorize("hasRole('ROLE_ADMIN')")
  @RequestMapping(value = "", method = DELETE)
  public ResponseEntity<Void> delete(@PathVariable("id") Long id) {
    int count = subscriptionRepository.countByFeedId(id);

    if (count > 0) {
      return ResponseEntity.status(HttpStatus.CONFLICT).build();
    }

    if (!feedRepository.exists(id)) {
      return ResponseEntity.notFound().build();
    }

    feedRepository.delete(id);

    return ResponseEntity.noContent().build();
  }
Exemplo n.º 20
0
  /**
   * Handles the GET request for downloading an artifact.
   *
   * @param downloadId the generated download id
   * @param response of the servlet
   * @return {@link ResponseEntity} with status {@link HttpStatus#OK} if successful
   */
  @RequestMapping(method = RequestMethod.GET, value = RestConstants.DOWNLOAD_ID_V1_REQUEST_MAPPING)
  @ResponseBody
  public ResponseEntity<Void> downloadArtifactByDownloadId(
      @PathVariable final String downloadId, final HttpServletResponse response) {
    try {
      final ValueWrapper cacheWrapper = cache.get(downloadId);
      if (cacheWrapper == null) {
        LOGGER.warn("Download Id {} could not be found", downloadId);
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
      }

      final DownloadArtifactCache artifactCache = (DownloadArtifactCache) cacheWrapper.get();
      DbArtifact artifact = null;
      switch (artifactCache.getDownloadType()) {
        case BY_SHA1:
          artifact = artifactRepository.getArtifactBySha1(artifactCache.getId());
          break;

        default:
          LOGGER.warn("Download Type {} not supported", artifactCache.getDownloadType());
          break;
      }

      if (artifact == null) {
        LOGGER.warn(
            "Artifact with cached id {} and download type {} could not be found.",
            artifactCache.getId(),
            artifactCache.getDownloadType());
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
      }
      try {
        IOUtils.copy(artifact.getFileInputStream(), response.getOutputStream());
      } catch (final IOException e) {
        LOGGER.error("Cannot copy streams", e);
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
      }
    } finally {
      cache.evict(downloadId);
    }

    return ResponseEntity.ok().build();
  }
  @RequestMapping(value = ERROR_PATH)
  public ResponseEntity<Map<String, Object>> error(HttpServletRequest request, Locale locale) {
    RequestAttributes requestAttributes = new ServletRequestAttributes(request);
    Map<String, Object> body = errorAttributes.getErrorAttributes(requestAttributes, true);

    HttpStatus status = HttpStatus.INTERNAL_SERVER_ERROR;
    if (Objects.nonNull(body.get("status"))) {
      try {
        status = HttpStatus.valueOf((Integer) body.get("status"));
      } catch (Exception ignore) {
      }
    }

    String message =
        messageSource.getMessage("error." + status, null, ERROR_DEFAULT_MESSAGE, locale);
    if (StringUtils.hasText(message)) {
      body.put("message", message);
    }

    return ResponseEntity.status(status).body(body);
  }
Exemplo n.º 22
0
  @RequestMapping(
      value = {"/ws/1.0/status/{requestId}"},
      method = RequestMethod.GET,
      produces = "application/json")
  public ResponseEntity<ReportResponse> status(@PathVariable("requestId") String requestId) {
    Status status = reportService.status(requestId);
    if (status == null) { // başlamamış
      logManager.info("status query :YOK !!! " + requestId);
      return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
    }
    logManager.info("status query :" + requestId);
    switch (status) {
      case WAIT:
        logManager.info("status query :" + requestId + " :başlamış");
        return ResponseEntity.status(HttpStatus.CREATED).body(null);

      case RUN:
        logManager.info("status query :" + requestId + " :devam ediyor");
        return ResponseEntity.status(HttpStatus.PROCESSING).body(null);

      case EXCEPTION:
        logManager.info("status query :" + requestId + " :hata");
        return ResponseEntity.status(420).body(null); // 420 Method Failure

      case FINISH:
        logManager.info("status query :" + requestId + " :bitmiş");
        return ResponseEntity.status(HttpStatus.OK).body(null);

      case CANCEL:
        logManager.info("status query :" + requestId + " :iptal");
        return ResponseEntity.status(HttpStatus.OK).body(null);

      case SCHEDULED:
        logManager.info("status query :" + requestId + " :başlamış");
        return ResponseEntity.status(HttpStatus.CREATED).body(null);
      default:
        throw new IllegalArgumentException(status.name());
    }
  }
Exemplo n.º 23
0
 @RequestMapping(value = "/collector/item", method = POST, consumes = JSON, produces = JSON)
 public ResponseEntity<CollectorItem> createCollectorItem(
     @Valid @RequestBody CollectorItemRequest request) {
   return ResponseEntity.status(HttpStatus.CREATED)
       .body(collectorService.createCollectorItem(request.toCollectorItem()));
 }