@ApiOperation("发帖接口") @ApiImplicitParams({ @ApiImplicitParam(name = "content", value = "帖子内容", dataType = "String"), @ApiImplicitParam(name = "title", value = "帖子标题", dataType = "String"), @ApiImplicitParam(name = "token", value = "用户令牌", dataType = "String"), @ApiImplicitParam(name = "labelId", value = "标签ID", dataType = "Integer") }) @PostMapping public QuarkResult CreatePosts(Posts posts, String token, Integer labelId) { QuarkResult result = restProcessor(() -> { if (token == null) return QuarkResult.warn("请先登录!"); User userbytoken = userService.getUserByToken(token); if (userbytoken == null) return QuarkResult.warn("用户不存在,请先登录!"); User user = userService.findOne(userbytoken.getId()); if (user.getEnable() != 1) return QuarkResult.warn("用户处于封禁状态!"); postsService.savePosts(posts, labelId, user); return QuarkResult.ok(); }); return result; }
private static Parameter createParameterInstance(ApiImplicitParam paramAnnotation) { switch (paramAnnotation.paramType()) { case "path": return new PathParameter(); case "query": return new QueryParameter(); case "body": return new BodyParameter(); case "header": return new HeaderParameter(); case "form": return new FormParameter(); case "cookie": return new CookieParameter(); default: throw new Error("not support paramType " + paramAnnotation.paramType()); } }
/** * 新增域 */ @RequestMapping(method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "新增域信息", notes = "添加新的域信息,新增的域默认授权给创建人") @ApiImplicitParam(name = "domain_id", value = "域编码", required = true, dataType = "String") public String add(HttpServletResponse response, HttpServletRequest request) { DomainEntity domainEntity = parse(request); RetMsg retMsg = domainService.add(domainEntity); if (retMsg.checkCode()) { return Hret.success(retMsg); } response.setStatus(retMsg.getCode()); return Hret.error(retMsg); }
@ApiOperation(value = "授权", notes = "") @ApiImplicitParams({ @ApiImplicitParam(paramType = "query",name = "appName", value = "应用的名字", required = true,dataType = "String"), @ApiImplicitParam(paramType = "query",name = "vq",value = "vq",required = true,dataType = "String"), @ApiImplicitParam(paramType = "query",name = "device",value = "设备的名字",required = true,dataType = "String")}) @RequestMapping(value = "${jwt.route.authentication.path}", method = RequestMethod.POST) public ResponseEntity<?> createAuthenticationToken(String appName,String vq, Device device) throws AuthenticationException { logger.info("应用:" + appName + " 正在授权!"); App app = appRepository.findFirstByAppname(appName); if (app == null) { return ResponseEntity.ok(new ErrorReporter(1, "未找到应用" + appName)); } YibanOAuth yibanOAuth = new YibanOAuth(vq, app); yibanOAuth.dealYibanOauth(); if (yibanOAuth.isHasError() == false) { upcYbUserFactory.createUser(yibanOAuth.getYibanBasicUserInfo()); String ybid = String.valueOf(yibanOAuth.getYibanBasicUserInfo().visit_user.userid); String ybtocken = yibanOAuth.getYibanBasicUserInfo().visit_oauth.access_token; logger.info("ybtocken: " + ybtocken); final JwtUser userDetails = (JwtUser) userDetailsService.loadUserByUsername(ybid); final String token = jwtTokenUtil.generateToken(userDetails, ybtocken,appName, device); logger.info("发放token:" + token); return ResponseEntity.ok(new JwtAuthenticationResponse(token)); } else { return ResponseEntity.ok(new ErrorReporter(2, "解析vq失败,可能是由于密钥长度不匹配")); } }
@ApiOperation("翻页查询帖子接口") @ApiImplicitParams({ @ApiImplicitParam(name = "search", value = "查询条件", dataType = "int"), @ApiImplicitParam(name = "type", value = "帖子类型[top : good : ]", dataType = "String"), @ApiImplicitParam(name = "pageNo", value = "页码[从1开始]", dataType = "int"), @ApiImplicitParam(name = "length", value = "返回结果数量[默认20]", dataType = "int") }) @GetMapping() public QuarkResult GetPosts( @RequestParam(required = false, defaultValue = "") String search, @RequestParam(required = false, defaultValue = "") String type, @RequestParam(required = false, defaultValue = "1") int pageNo, @RequestParam(required = false, defaultValue = "20") int length) { QuarkResult result = restProcessor(() -> { if (!type.equals("good") && !type.equals("top") && !type.equals("")) return QuarkResult.error("类型错误!"); Page<Posts> page = postsService.getPostsByPage(type, search, pageNo - 1, length); return QuarkResult.ok(page.getContent(), page.getTotalElements(), page.getNumberOfElements()); }); return result; }
@ApiOperation("翻页帖子详情与回复接口") @ApiImplicitParams({ @ApiImplicitParam(name = "postsid", value = "帖子的id", dataType = "int"), @ApiImplicitParam(name = "pageNo", value = "页码[从1开始]", dataType = "int"), @ApiImplicitParam(name = "length", value = "返回结果数量[默认20]", dataType = "int") }) @GetMapping("/detail/{postsid}") public QuarkResult GetPostsDetail( @PathVariable("postsid") Integer postsid, @RequestParam(required = false, defaultValue = "1") int pageNo, @RequestParam(required = false, defaultValue = "20") int length) { QuarkResult result = restProcessor(() -> { HashMap<String, Object> map = new HashMap<>(); Posts posts = postsService.findOne(postsid); if (posts == null) return QuarkResult.error("帖子不存在"); map.put("posts", posts); Page<Reply> page = replyService.getReplyByPage(postsid, pageNo - 1, length); map.put("replys", page.getContent()); return QuarkResult.ok(map, page.getTotalElements(), page.getNumberOfElements()); }); return result; }
@ApiOperation("根据labelId获取帖子接口") @ApiImplicitParams({ @ApiImplicitParam(name = "labelid", value = "标签的id", dataType = "int"), @ApiImplicitParam(name = "pageNo", value = "页码[从1开始]", dataType = "int"), @ApiImplicitParam(name = "length", value = "返回结果数量[默认20]", dataType = "int"), }) @GetMapping("/label/{labelid}") public QuarkResult GetPostsByLabel( @PathVariable("labelid") Integer labelid, @RequestParam(required = false, defaultValue = "1") int pageNo, @RequestParam(required = false, defaultValue = "20") int length) { QuarkResult result = restProcessor(() -> { Label label = labelService.findOne(labelid); if (label == null) return QuarkResult.error("标签不存在"); Page<Posts> page = postsService.getPostsByLabel(label, pageNo - 1, length); return QuarkResult.ok(page.getContent(), page.getTotalElements(), page.getNumberOfElements()); }); return result; }
@ApiOperation("注册接口") @ApiImplicitParams({ @ApiImplicitParam(name = "email", value = "用户邮箱",dataType = "String"), @ApiImplicitParam(name = "username", value = "用户名称",dataType = "String"), @ApiImplicitParam(name = "password", value = "用户密码",dataType = "String") }) @PostMapping public QuarkResult checkUserName(String email,String username,String password) { QuarkResult result = restProcessor(() -> { if (!userService.checkUserName(username)) return QuarkResult.warn("用户名已存在,请重新输入"); if (!userService.checkUserEmail(email)) return QuarkResult.warn("用户邮箱已存在,请重新输入"); else userService.createUser(email,username,password); return QuarkResult.ok(); }); return result; }
@ApiOperation("登录接口") @ApiImplicitParams({ @ApiImplicitParam(name = "email", value = "用户邮箱",dataType = "String"), @ApiImplicitParam(name = "password", value = "用户密码",dataType = "String") }) @PostMapping("/login") public QuarkResult Login(String email,String password) { QuarkResult result = restProcessor(() -> { User loginUser = userService.findByEmail(email); if (loginUser == null) return QuarkResult.warn("用户邮箱不存在,请重新输入"); if (!loginUser.getPassword().equals(DigestUtils.md5DigestAsHex(password.getBytes()))) return QuarkResult.warn("用户密码错误,请重新输入"); String token = userService.LoginUser(loginUser); return QuarkResult.ok(token); }); return result; }
@ApiOperation("根据Token获取用户的信息与通知消息数量") @ApiImplicitParams({ @ApiImplicitParam(name = "token", value = "发送给用户的唯一令牌",dataType = "String"), }) @GetMapping("/message/{token}") public QuarkResult getUserAndMessageByToken(@PathVariable String token){ QuarkResult result = restProcessor(() -> { HashMap<String, Object> map = new HashMap<>(); User user = userService.getUserByToken(token); if (user == null) return QuarkResult.warn("session过期,请重新登录"); long count = notificationService.getNotificationCount(user.getId()); map.put("user",user); map.put("messagecount",count); return QuarkResult.ok(map); }); return result; }
@ApiOperation("根据Token修改用户的信息") @ApiImplicitParams({ @ApiImplicitParam(name = "token", value = "发送给用户的唯一令牌",dataType = "String"), @ApiImplicitParam(name = "username", value = "要修改的用户名",dataType = "String"), @ApiImplicitParam(name = "signature", value = "用户签名",dataType = "String"), @ApiImplicitParam(name = "sex", value = "要修改的性别:数值0为男,1为女",dataType = "int"), }) @PutMapping("/{token}") public QuarkResult updateUser(@PathVariable("token") String token,String username,String signature,Integer sex){ QuarkResult result = restProcessor(() -> { if (!userService.checkUserName(username)) return QuarkResult.warn("用户名重复!"); if (sex != 0 && sex != 1) return QuarkResult.warn("性别输入错误!"); userService.updateUser(token, username, signature, sex); return QuarkResult.ok(); }); return result; }
@ApiOperation("根据用户ID获取用户详情与用户最近发布的十个帖子[主要用于用户主页展示]") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "用户的id", dataType = "int") }) @GetMapping("/detail/{userid}") public QuarkResult getUserById(@PathVariable("userid") Integer userid){ QuarkResult result = restProcessor(() -> { User user = userService.findOne(userid); if (user == null || userid == null) return QuarkResult.warn("用户不存在"); List<Posts> postss = postsService.getPostsByUser(user); HashMap<String, Object> map = new HashMap<>(); map.put("posts",postss); map.put("user",user); return QuarkResult.ok(map); }); return result; }
@ApiOperation(value = "getOrganisationByName", nickname = "getOrganisationByName") @RequestMapping(value = "/CISConnector/getOrganisationByName/{organisation}", method = RequestMethod.GET) @ApiImplicitParams({ @ApiImplicitParam(name = "organisation", value = "the Organisation name", required = true, dataType = "String", paramType = "path") }) @ApiResponses(value = { @ApiResponse(code = 200, message = "Success", response = ResponseEntity.class), @ApiResponse(code = 400, message = "Bad Request", response = ResponseEntity.class), @ApiResponse(code = 500, message = "Failure", response = ResponseEntity.class)}) public ResponseEntity<Organisation> getOrganisationByName(@PathVariable String organisation) throws CISCommunicationException { log.info("--> getOrganisationByName: " + organisation); Organisation organisationRes = null; try { organisationRes = connector.getOrganisationByName(organisation); } catch (CISCommunicationException e) { log.error("Error executing the request: Communication Error" , e); organisationRes = null; } HttpHeaders responseHeaders = new HttpHeaders(); log.info("getOrganisationByName -->"); return new ResponseEntity<Organisation>(organisationRes, responseHeaders, HttpStatus.OK); }
@ApiOperation("发布回复接口") @ApiImplicitParams({ @ApiImplicitParam(name = "content", value = "回复内容", dataType = "String"), @ApiImplicitParam(name = "token", value = "用户令牌", dataType = "String"), @ApiImplicitParam(name = "postsId", value = "帖子ID", dataType = "Integer") }) @PostMapping public QuarkResult CreateReply(Reply reply,Integer postsId,String token){ QuarkResult result = restProcessor(() -> { if (token == null) return QuarkResult.warn("请先登录!"); User userbytoken = userService.getUserByToken(token); if (userbytoken == null) return QuarkResult.warn("用户不存在,请先登录!"); User user = userService.findOne(userbytoken.getId()); if (user.getEnable() != 1) return QuarkResult.warn("用户处于封禁状态!"); replyService.saveReply(reply, postsId, user); return QuarkResult.ok(); }); return result; }
/** * 注册 */ @AuthIgnore @PostMapping("register") @ApiOperation(value = "注册") @ApiImplicitParams({ @ApiImplicitParam(paramType = "query", dataType = "string", name = "mobile", value = "手机号", required = true), @ApiImplicitParam(paramType = "query", dataType = "string", name = "password", value = "密码", required = true) }) public Result register(String mobile, String password) { Assert.isBlank(mobile, "手机号不能为空"); Assert.isBlank(password, "密码不能为空"); try { userService.save(mobile, password); } catch (Exception e) { log.error("注册异常", e); return Result.error("注册异常"); } return Result.ok(); }
@ApiOperation(value = "getParticipantFromCGOR", nickname = "getParticipantFromCGOR") @RequestMapping(value = "/CISConnector/getParticipantFromCGOR/{cgorName}", method = RequestMethod.GET) @ApiImplicitParams({ @ApiImplicitParam(name = "cgorName", value = "the CGOR name", required = true, dataType = "String", paramType = "path"), @ApiImplicitParam(name = "organisation", value = "the Organisation name", required = true, dataType = "String", paramType = "query") }) @ApiResponses(value = { @ApiResponse(code = 200, message = "Success", response = Participant.class), @ApiResponse(code = 400, message = "Bad Request", response = Participant.class), @ApiResponse(code = 500, message = "Failure", response = Participant.class)}) public ResponseEntity<Participant> getParticipantFromCGOR(@PathVariable String cgorName, @QueryParam("organisation") String organisation) { log.info("--> getParticipantFromCGOR: " + cgorName); Participant participant; try { participant = connector.getParticipantFromCGOR(cgorName, organisation); } catch (CISCommunicationException e) { log.error("Error executing the request: Communication Error" , e); participant = null; } HttpHeaders responseHeaders = new HttpHeaders(); log.info("getParticipantFromCGOR -->"); return new ResponseEntity<Participant>(participant, responseHeaders, HttpStatus.OK); }
/** * 登录 */ @AuthIgnore @PostMapping("login") @ApiOperation(value = "登录",notes = "登录说明") @ApiImplicitParams({ @ApiImplicitParam(paramType = "query", dataType="string", name = "mobile", value = "手机号", required = true), @ApiImplicitParam(paramType = "query", dataType="string", name = "password", value = "密码", required = true) }) public R login(String mobile, String password){ Assert.isBlank(mobile, "手机号不能为空"); Assert.isBlank(password, "密码不能为空"); //用户登录 long userId = userService.login(mobile, password); //生成token Map<String, Object> map = tokenService.createToken(userId); return R.ok(map); }
/** * 注册 */ @AuthIgnore @PostMapping("register") @ApiOperation(value = "注册") @ApiImplicitParams({ @ApiImplicitParam(paramType = "query", dataType="string", name = "mobile", value = "手机号", required = true), @ApiImplicitParam(paramType = "query", dataType="string", name = "password", value = "密码", required = true) }) public R register(String mobile, String password){ Assert.isBlank(mobile, "手机号不能为空"); Assert.isBlank(password, "密码不能为空"); userService.save(mobile, password); return R.ok(); }
/** * Put test exec config. */ @Override @Path("/config") @ApiOperation(value="Update test exec config.", response=StatusMessage.class) @ApiImplicitParams({ @ApiImplicitParam(name="TestExecConfig", paramType="body", dataType="com.centurylink.mdw.test.TestExecConfig")}) public JSONObject put(String path, JSONObject content, Map<String,String> headers) throws ServiceException, JSONException { if (ApplicationContext.isMasterServer() || headers.get(Listener.METAINFO_MASTER_OP) != null) { TestingServices testingServices = ServiceLocator.getTestingServices(); testingServices.setTestExecConfig(new TestExecConfig(content)); return null; } else { return masterServerPut(path, content); } }
@ApiOperation(value = "session/user", nickname = "get session user", notes = "get session user") @ApiResponses({ @ApiResponse(code = 200, message = "Success"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 500, message = "Failure") }) @ApiImplicitParams({ @ApiImplicitParam(name = "search", value = "Name to search", paramType = "query"), @ApiImplicitParam(name = "exclude_hidden", value = "Do not return hidden skills", paramType = "query", defaultValue = "true"), @ApiImplicitParam(name = "count", value = "Limit the number of skills to find", paramType = "query"), }) @RequestMapping(path = "/session/user", method = RequestMethod.GET) public ResponseEntity<String> getCurrentUser(@CookieValue("_oauth2_proxy") String oAuthToken) { logger.debug("Getting user from session {}", oAuthToken); User user = sessionService.getUserByToken(oAuthToken); if (user == null) { return new ResponseEntity<>(new StatusJSON("no current session").toString(), HttpStatus.UNAUTHORIZED); } return new ResponseEntity<>(user.toJSON().toString(), HttpStatus.OK); }
/** * get/suggest skills based on search query -> can be used for autocompletion when user started * typing */ @ApiOperation(value = "suggest skills", nickname = "suggest skills", notes = "suggest skills") @ApiResponses({ @ApiResponse(code = 200, message = "Success"), @ApiResponse(code = 500, message = "Failure") }) @ApiImplicitParams({ @ApiImplicitParam(name = "search", value = "Name to search", paramType = "query"), @ApiImplicitParam(name = "exclude_hidden", value = "Do not return hidden skills", paramType = "query", defaultValue = "true"), @ApiImplicitParam(name = "count", value = "Limit the number of skills to find", paramType = "query"), }) @RequestMapping(path = "/skills", method = RequestMethod.GET) public ResponseEntity<String> getSkills(@RequestParam(required = false) String search, @RequestParam(required = false, defaultValue = "true") boolean exclude_hidden, @RequestParam(required = false, defaultValue = "-1") int count) { JSONArray skillsArr = new JSONArray( skillService.getSkills(search, exclude_hidden, count) .stream() .map(KnownSkill::toJSON) .collect(Collectors.toList()) ); return new ResponseEntity<>(skillsArr.toString(), HttpStatus.OK); }
/** * Overrides {@link MoviesService#get()} to return a single movie with the specified id. */ @Override @ApiOperation(value="Retrieve a movie by {id}", response=Movie.class) @ApiImplicitParams({ @ApiImplicitParam(name="id", paramType="path", dataType="string", required=true)}) public Response<JSONObject> get(Request<JSONObject> request) throws ServiceException { validate(request); String id = request.getPath().getSegment(1); Movie movie = getPersist().get(id); if (movie == null) throw new ServiceException(Status.NOT_FOUND, "Movie not found with id: " + id); else return new Response<>(movie.toJson()); }
@Override @ApiOperation(value="Update a movie.", response=StatusResponse.class) @ApiImplicitParams({ @ApiImplicitParam(name="id", paramType="path", dataType="string", required=true), @ApiImplicitParam(name="Movie", paramType="body", dataType="io.limberest.demo.model.Movie", required=true)}) public Response<JSONObject> put(Request<JSONObject> request) throws ServiceException { validate(request); String id = request.getPath().getSegment(1); if (id == null) throw new ServiceException(Status.BAD_REQUEST, "Missing path segment: id"); Movie movie = new Movie(request.getBody()); if (movie.getId() != null && !id.equals(movie.getId())) throw new ServiceException(Status.BAD_REQUEST, "Cannot modify movie id: " + id); if (movie.getId() == null) movie = new Movie(id, movie); getPersist().update(movie); StatusResponse statusResponse = new StatusResponse(Status.OK, "Movie updated: " + movie.getId()); return new Response<>(statusResponse.toJson()); }
@ApiOperation(value = "getOrganisationByName", nickname = "getOrganisationByName") @RequestMapping(value = "/CISCore/getOrganisationByName/{organisation}", method = RequestMethod.GET) @ApiImplicitParams({ @ApiImplicitParam(name = "organisation", value = "the Organisation name", required = true, dataType = "String", paramType = "query") }) @ApiResponses(value = { @ApiResponse(code = 200, message = "Success", response = ResponseEntity.class), @ApiResponse(code = 400, message = "Bad Request", response = ResponseEntity.class), @ApiResponse(code = 500, message = "Failure", response = ResponseEntity.class)}) public ResponseEntity<Organisation> getOrganisationByName(@PathVariable String organisation) throws CISCommunicationException { log.info("--> getOrganisationByName: " + organisation); Organisation organisationRes = null; organisationRes = cisCore.getOrganisationByName(organisation); HttpHeaders responseHeaders = new HttpHeaders(); log.info("getOrganisationByName -->"); return new ResponseEntity<Organisation>(organisationRes, responseHeaders, HttpStatus.OK); }
/** * 新增域 */ @RequestMapping(method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "新增域信息", notes = "添加新的域信息,新增的域默认授权给创建人") @ApiImplicitParam(name = "domain_id", value = "域编码", required = true, dataType = "String") public String add(@Validated DomainEntity domainEntity, BindingResult bindingResult, HttpServletResponse response, HttpServletRequest request) { if (bindingResult.hasErrors()) { for (ObjectError m : bindingResult.getAllErrors()) { response.setStatus(421); return Hret.error(421, m.getDefaultMessage(), null); } } String userId = JwtService.getConnUser(request).getUserId(); domainEntity.setDomainModifyUser(userId); domainEntity.setCreateUserId(userId); RetMsg retMsg = domainService.add(domainEntity); if (retMsg.checkCode()) { return Hret.success(retMsg); } response.setStatus(retMsg.getCode()); return Hret.error(retMsg); }
@ApiOperation(value="admin-获取文章列表") @ApiImplicitParams({ @ApiImplicitParam(name = "keyword", value = "查询关键字", required = false), @ApiImplicitParam(name = "pageNum", value = "页码", defaultValue="1", required = false), @ApiImplicitParam(name = "pageSize", value = "页大小", defaultValue="10",required = false) }) @GetMapping public RestResponse getArticles(@ModelAttribute SearchArticleParam searchArticleParam) { Page<Article> articles = null; if (Strings.isNullOrEmpty(searchArticleParam.getKeyword())) { articles = articleService.getArticleByPage(searchArticleParam.getPageNum(), searchArticleParam.getPageSize()); }else { articles = articleService.getArticleByTitle(searchArticleParam.getPageNum(), searchArticleParam.getPageSize(), searchArticleParam.getKeyword()); } return RestResponse.success(articles); }
@ApiOperation(value = "更新系统参数", notes = "更新结果只对当前操作的域有效") @ApiImplicitParams({ @ApiImplicitParam(required = true, name = "domain_id", value = "域编码"), @ApiImplicitParam(required = true, name = "config_id", value = "参数编码"), @ApiImplicitParam(required = true, name = "config_value", value = "参数值"), }) @RequestMapping(value = "/v1/dispatch/config/user", method = RequestMethod.POST) public String updateConfigValue(HttpServletResponse response, HttpServletRequest request) { String domainId = request.getParameter("domain_id"); String configId = request.getParameter("config_id"); String configValue = request.getParameter("config_value"); int size = sysConfigService.setValue(domainId, configId, configValue); if (size != 1) { response.setStatus(421); return Hret.error(421, "更新ETL调度系统核心参数失败", null); } return Hret.success(200, "success", null); }
@ApiOperation(value = "getOrganisationInvitations", nickname = "getOrganisationInvitations") @RequestMapping(value = "/CISCore/getOrganisationInvitations/{organisation}", method = RequestMethod.GET) @ApiImplicitParams({ @ApiImplicitParam(name = "organisation", value = "the Organisation name", required = true, dataType = "String", paramType = "path") }) @ApiResponses(value = { @ApiResponse(code = 200, message = "Success", response = ResponseEntity.class), @ApiResponse(code = 400, message = "Bad Request", response = ResponseEntity.class), @ApiResponse(code = 500, message = "Failure", response = ResponseEntity.class)}) public ResponseEntity<List<CgorInvitation>> getOrganisationInvitations(String organisation) throws CISCommunicationException { log.info("--> getOrganisationInvitations"); List<CgorInvitation> cgorInvitationList = new ArrayList<CgorInvitation>(); try { cgorInvitationList = cisCore.getOrganisationInvitations(organisation); } catch (CISCommunicationException e) { log.error("Error executing the request: Communication Error" , e); cgorInvitationList = null; } HttpHeaders responseHeaders = new HttpHeaders(); log.info("getOrganisationInvitations -->"); return new ResponseEntity<List<CgorInvitation>>(cgorInvitationList, responseHeaders, HttpStatus.OK); }
@ApiOperation(value="分页查询表单内容", notes="根据传进来的查询参数,获取表单内容信息") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "主键ID", required = false, dataType = "int", paramType = "query"), @ApiImplicitParam(name = "businessKey", value = "业务主键KEY,模糊匹配", required = false, dataType = "string", paramType = "query"), @ApiImplicitParam(name = "key", value = "内容键,模糊匹配", required = false, dataType = "string", paramType = "query"), @ApiImplicitParam(name = "value", value = "内容值,模糊匹配", required = false, dataType = "string", paramType = "query"), @ApiImplicitParam(name = "tenantId", value = "租户ID,模糊匹配", required = false, dataType = "string", paramType = "query"), @ApiImplicitParam(name = "page", value = "分页查询,开始查询的页码", defaultValue="0", required = false, dataType = "int", paramType = "query"), @ApiImplicitParam(name = "size", value = "分页查询,每页显示的记录数", defaultValue="10", required = false, dataType = "int", paramType = "query"), @ApiImplicitParam(name = "sort", value = "排序的字段,可以多值以逗号分割", required = false, dataType = "string", paramType = "query"), @ApiImplicitParam(name = "order", value = "排序的方式,可以为asc或desc,可以多值以逗号分割", required = false, dataType = "string", paramType = "query") }) @RequestMapping(value = "/form-datas", method = RequestMethod.GET, produces = "application/json") @ResponseStatus(value = HttpStatus.OK) public Page<FormData> getFormDatas(@ApiIgnore @RequestParam Map<String, String> requestParams) { Criteria<FormData> criteria = new Criteria<FormData>(); criteria.add(Restrictions.eq("id", requestParams.get("id"), true)); criteria.add(Restrictions.like("businessKey", requestParams.get("businessKey"), true)); criteria.add(Restrictions.like("key", requestParams.get("key"), true)); criteria.add(Restrictions.like("value", requestParams.get("value"), true)); criteria.add(Restrictions.like("tenantId", requestParams.get("tenantId"), true)); return formDataRepository.findAll(criteria, getPageable(requestParams)); }
@ApiOperation(value="创建表单内容", notes="根据传过来的formDataRequest信息来创建表单内容") @ApiImplicitParam(name = "formDataRequest", value = "表单内容请求实体formDataRequest", required = true, dataType = "FormDataRequest") @RequestMapping(value = "/form-datas", method = RequestMethod.POST, produces = "application/json") @ResponseStatus(value = HttpStatus.CREATED) @Transactional(propagation = Propagation.REQUIRED) public FormData createFormData(@RequestBody FormDataRequest formDataRequest){ FormData formData = new FormData(); if(formDataRequest.getKey() != null){ formData.setKey(formDataRequest.getKey()); } if(formDataRequest.getValue() != null){ formData.setValue(formDataRequest.getValue()); } if(formDataRequest.getBusinessKey() != null){ // formData.setBusinessKey(formDataRequest.getBusinessKey()); } if(formDataRequest.getTenantId() != null){ formData.setTenantId(formDataRequest.getTenantId()); } return formDataRepository.save(formData); }
@ApiOperation(value="更新表单内容", notes="根据表单内容的id来指定更新对象,并根据传过来的formDataRequest信息来更新表单内容") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "表单内容ID", required = true, dataType = "Long",paramType="path"), @ApiImplicitParam(name = "formDataRequest", value = "表单内容请求实体formDataRequest", required = true, dataType = "FormDataRequest") }) @RequestMapping(value = "/form-datas/{id}", method = RequestMethod.PUT, produces = "application/json") @ResponseStatus(value = HttpStatus.OK) public FormData updateFormData(@PathVariable Long id,@RequestBody FormDataRequest formDataRequest) throws InterruptedException { FormData formData = getFormDataFromRequest(id); if(formDataRequest.getKey() != null){ formData.setKey(formDataRequest.getKey()); } if(formDataRequest.getValue() != null){ formData.setValue(formDataRequest.getValue()); } if(formDataRequest.getBusinessKey() != null){ // formData.setBusinessKey(formDataRequest.getBusinessKey()); } if(formDataRequest.getTenantId() != null){ formData.setTenantId(formDataRequest.getTenantId()); } return formDataRepository.save(formData); }
@ApiOperation(value = "分页查询表单模型", notes = "根据传进来的查询参数,获取表单模型信息") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "主键ID", required = false, dataType = "int", paramType = "query"), @ApiImplicitParam(name = "category", value = "模型分类,模糊匹配", required = false, dataType = "string", paramType = "query"), @ApiImplicitParam(name = "key", value = "模型键,模糊匹配", required = false, dataType = "string", paramType = "query"), @ApiImplicitParam(name = "name", value = "模型名称,模糊匹配", required = false, dataType = "string", paramType = "query"), @ApiImplicitParam(name = "tenantId", value = "租户ID,模糊匹配", required = false, dataType = "string", paramType = "query"), @ApiImplicitParam(name = "pageNum", value = "分页查询开始查询的页码", defaultValue = "1", required = false, dataType = "int", paramType = "query"), @ApiImplicitParam(name = "pageSize", value = "分页查询每页显示的记录数", defaultValue = "10", required = false, dataType = "int", paramType = "query"), @ApiImplicitParam(name = "sortName", value = "排序的字段,可以多值以逗号分割", required = false, dataType = "string", paramType = "query"), @ApiImplicitParam(name = "sortOrder", value = "排序的方式,可以为asc或desc,可以多值以逗号分割", required = false, dataType = "string", paramType = "query") }) @RequestMapping(value = "/form-models", method = RequestMethod.GET, produces = "application/json") @ResponseStatus(value = HttpStatus.OK) public PageResponse<FormModelResponse> getFormModels(@ApiIgnore @RequestParam Map<String, String> requestParams) { Criteria<FormModel> criteria = new Criteria<FormModel>(); criteria.add(Restrictions.eq("id", requestParams.get("id"), true)); criteria.add(Restrictions.like("category", requestParams.get("category"), true)); criteria.add(Restrictions.like("key", requestParams.get("key"), true)); criteria.add(Restrictions.like("name", requestParams.get("name"), true)); criteria.add(Restrictions.like("tenantId", requestParams.get("tenantId"), true)); return responseFactory.createFormModelPageResponse(formModelRepository.findAll(criteria, getPageable(requestParams))); }
@Path("/reduce") @GET @ApiImplicitParams({ @ApiImplicitParam(name = "a", dataType = "integer", format = "int32", paramType = "query")}) public int reduce(HttpServletRequest request, @CookieParam("b") int b) { int a = Integer.parseInt(request.getParameter("a")); return a - b; }
@Path("/reduce") @GET @ApiImplicitParams({@ApiImplicitParam(name = "a", dataType = "integer", format = "int32", paramType = "query")}) public int reduce(HttpServletRequest request, @CookieParam("b") int b) { int a = Integer.parseInt(request.getParameter("a")); return a - b; }
@PostMapping(path = "/testform") @ApiImplicitParams({ @ApiImplicitParam(name = "form1", dataType = "string", paramType = "form", value = "a required form param", required = true), @ApiImplicitParam(name = "form2", dataType = "string", paramType = "form", value = "an optional form param", required = false)}) public String testform(HttpServletRequest request) { String form1 = request.getParameter("form1"); String form2 = request.getParameter("form2"); Assert.notNull(form1); return form1 + form2; }
@Override public void process(Object annotation, SwaggerGenerator swaggerGenerator) { ApiImplicitParam paramAnnotation = (ApiImplicitParam) annotation; Parameter parameter = AnnotationUtils.createParameter(swaggerGenerator.getSwagger(), paramAnnotation); swaggerGenerator.getSwagger().addParameter(parameter.getName(), parameter); }
public static Parameter createParameter(Swagger swagger, ApiImplicitParam paramAnnotation) { Parameter parameter = createParameterInstance(paramAnnotation); Type dataType = ReflectionUtils.typeFromString(paramAnnotation.dataType()); parameter = ParameterProcessor.applyAnnotations(swagger, parameter, dataType, Arrays.asList(paramAnnotation)); return parameter; }
@Override public void process(Object annotation, OperationGenerator operationGenerator) { ApiImplicitParams apiImplicitParamsAnnotation = (ApiImplicitParams) annotation; MethodAnnotationProcessor processor = operationGenerator.getContext().findMethodAnnotationProcessor(ApiImplicitParam.class); for (ApiImplicitParam paramAnnotation : apiImplicitParamsAnnotation.value()) { processor.process(paramAnnotation, operationGenerator); } }
@Override public void process(Object annotation, SwaggerGenerator swaggerGenerator) { ApiImplicitParams apiImplicitParamsAnnotation = (ApiImplicitParams) annotation; ClassAnnotationProcessor processor = swaggerGenerator.getContext().findClassAnnotationProcessor(ApiImplicitParam.class); for (ApiImplicitParam paramAnnotation : apiImplicitParamsAnnotation.value()) { processor.process(paramAnnotation, swaggerGenerator); } }
@Override public void process(Object annotation, OperationGenerator operationGenerator) { ApiImplicitParam paramAnnotation = (ApiImplicitParam) annotation; Parameter parameter = AnnotationUtils.createParameter(operationGenerator.getSwagger(), paramAnnotation); operationGenerator.addMethodAnnotationParameter(parameter); }