Пример #1
0
 @RequestMapping(value = "api/{idString}/exprs", method = RequestMethod.GET)
 public @ResponseBody List<ExprDTO> getAllExprs(@PathVariable("idString") String idString) {
   // Get all collections
   List<Collection> collections = collectionRepository.findAllByOwner(idString);
   // Get all exprs
   List<Long> exprIds = new ArrayList<Long>();
   for (Collection collection : collections) {
     exprIds.add(collection.getExprId());
   }
   List<Expr> exprs = exprRepository.findAllByIdIn(exprIds);
   // Put collections into exprs
   List<ExprDTO> exprDTOs = new ArrayList<ExprDTO>();
   Map<Long, ExprDTO> exprDTOMap = new HashMap<Long, ExprDTO>();
   for (Expr expr : exprs) {
     ExprDTO exprDTO = new ExprDTO(expr);
     exprDTOs.add(exprDTO);
     exprDTOMap.put(exprDTO.getId(), exprDTO);
   }
   for (Collection collection : collections) {
     if (collection.getContent().length() > 0) {
       exprDTOMap.get(collection.getExprId()).tags.add(collection.getContent());
     }
   }
   return exprDTOs;
 }
Пример #2
0
  @RequestMapping(value = "api/{idString}/exprs/my", method = RequestMethod.GET)
  public @ResponseBody List<Expr> getMyExprsBycollection(
      @PathVariable("idString") String idString,
      @RequestParam(value = "tag") String content,
      HttpServletRequest request) {
    Visit visit = new Visit();
    visit.setCreated(new Date());
    visit.setUserId(idString);
    visit.setVisitUrl(request.getRequestURL().toString());
    visit.setClientIp(request.getRemoteAddr());
    visitRepository.save(visit);

    List<Collection> collections = collectionRepository.findAllByOwnerAndContent(idString, content);
    List<Long> exprIds = new ArrayList<Long>();
    for (Collection collection : collections) {
      exprIds.add(collection.getExprId());
    }
    List<Expr> exprs = exprRepository.findAllByIdIn(exprIds);
    for (Expr expr : exprs) {
      expr.eraseDangerousInfo();
    }
    return exprs;
  }