Search in sources :

Example 1 with PageResultDto

use of io.jpom.model.PageResultDto in project Jpom by dromara.

the class RepositoryController method giteeRepos.

/**
 * gitee 仓库
 *
 * @param token 个人令牌
 * @param page  分页
 * @return page
 */
private PageResultDto<JSONObject> giteeRepos(String token, Page page) {
    // 
    HttpResponse userResponse = HttpUtil.createGet("https://gitee.com/api/v5/user").form("access_token", token).execute();
    Assert.state(userResponse.isOk(), "令牌不正确:" + userResponse.body());
    JSONObject userBody = JSONObject.parseObject(userResponse.body());
    String username = userBody.getString("login");
    // 拉取仓库信息
    HttpResponse reposResponse = HttpUtil.createGet("https://gitee.com/api/v5/user/repos").form("access_token", token).form("sort", "pushed").form("page", page.getPageNumber()).form("per_page", page.getPageSize()).execute();
    String body = reposResponse.body();
    Assert.state(userResponse.isOk(), "拉取仓库信息错误:" + body);
    String totalCountStr = reposResponse.header("total_count");
    int totalCount = Convert.toInt(totalCountStr, 0);
    // String totalPage = reposResponse.header("total_page");
    JSONArray jsonArray = JSONArray.parseArray(body);
    List<JSONObject> objects = jsonArray.stream().map(o -> {
        JSONObject repo = (JSONObject) o;
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name", repo.getString("name"));
        String htmlUrl = repo.getString("html_url");
        jsonObject.put("url", htmlUrl);
        jsonObject.put("full_name", repo.getString("full_name"));
        jsonObject.put("private", repo.getBooleanValue("private"));
        jsonObject.put("description", repo.getString("description"));
        // 
        jsonObject.put("username", username);
        jsonObject.put("exists", RepositoryController.this.checkRepositoryUrl(null, htmlUrl));
        return jsonObject;
    }).collect(Collectors.toList());
    // 
    PageResultDto<JSONObject> pageResultDto = new PageResultDto<>(page.getPageNumber(), page.getPageSize(), totalCount);
    pageResultDto.setResult(objects);
    return pageResultDto;
}
Also used : PageResultDto(io.jpom.model.PageResultDto) BuildUtil(io.jpom.build.BuildUtil) DefaultSystemLog(cn.jiangzeyin.common.DefaultSystemLog) io.jpom.plugin(io.jpom.plugin) Page(cn.hutool.db.Page) Feature(io.jpom.permission.Feature) ServletUtil(cn.hutool.extra.servlet.ServletUtil) JpomRuntimeException(io.jpom.system.JpomRuntimeException) JsonMessage(cn.jiangzeyin.common.JsonMessage) JSONArray(com.alibaba.fastjson.JSONArray) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpUtil(cn.hutool.http.HttpUtil) HttpResponse(cn.hutool.http.HttpResponse) Map(java.util.Map) GetMapping(org.springframework.web.bind.annotation.GetMapping) URLUtil(cn.hutool.core.util.URLUtil) MethodFeature(io.jpom.permission.MethodFeature) HttpRequest(cn.hutool.http.HttpRequest) PostMapping(org.springframework.web.bind.annotation.PostMapping) RepositoryService(io.jpom.service.dblog.RepositoryService) ClassFeature(io.jpom.permission.ClassFeature) RestController(org.springframework.web.bind.annotation.RestController) Collectors(java.util.stream.Collectors) File(java.io.File) HttpStatus(org.springframework.http.HttpStatus) Tuple(cn.hutool.core.lang.Tuple) StrUtil(cn.hutool.core.util.StrUtil) List(java.util.List) ValidatorItem(cn.jiangzeyin.common.validator.ValidatorItem) RepositoryModel(io.jpom.model.data.RepositoryModel) Const(io.jpom.common.Const) BuildInfoService(io.jpom.service.dblog.BuildInfoService) Convert(cn.hutool.core.convert.Convert) FileUtil(cn.hutool.core.io.FileUtil) JSONObject(com.alibaba.fastjson.JSONObject) Entity(cn.hutool.db.Entity) GitProtocolEnum(io.jpom.model.enums.GitProtocolEnum) BaseServerController(io.jpom.common.BaseServerController) Validator(cn.hutool.core.lang.Validator) Assert(org.springframework.util.Assert) JSONObject(com.alibaba.fastjson.JSONObject) JSONArray(com.alibaba.fastjson.JSONArray) HttpResponse(cn.hutool.http.HttpResponse) PageResultDto(io.jpom.model.PageResultDto)

Example 2 with PageResultDto

use of io.jpom.model.PageResultDto in project Jpom by dromara.

the class RepositoryController method gitlabRepos.

/**
 * gitlab 仓库
 * <p>
 * https://docs.gitlab.com/ee/api/projects.html#list-all-projects
 *
 * @param token 个人令牌
 * @param page  分页
 * @return page
 */
private PageResultDto<JSONObject> gitlabRepos(String token, Page page) {
    // 
    HttpResponse userResponse = HttpUtil.createGet("https://gitlab.com/api/v4/user").form("access_token", token).execute();
    Assert.state(userResponse.isOk(), "令牌不正确:" + userResponse.body());
    JSONObject userBody = JSONObject.parseObject(userResponse.body());
    String username = userBody.getString("username");
    // 拉取仓库信息
    HttpResponse reposResponse = HttpUtil.createGet("https://gitlab.com/api/v4/projects").form("private_token", token).form("membership", true).form("simple", true).form("order_by", "updated_at").form("page", page.getPageNumber()).form("per_page", Math.max(page.getPageSize(), 15)).execute();
    String body = reposResponse.body();
    Assert.state(userResponse.isOk(), "拉取仓库信息错误:" + body);
    String totalCountStr = reposResponse.header("X-Total");
    int totalCount = Convert.toInt(totalCountStr, 0);
    // String totalPage = reposResponse.header("total_page");
    JSONArray jsonArray = JSONArray.parseArray(body);
    List<JSONObject> objects = jsonArray.stream().map(o -> {
        JSONObject repo = (JSONObject) o;
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name", repo.getString("name"));
        String htmlUrl = repo.getString("http_url_to_repo");
        jsonObject.put("url", htmlUrl);
        jsonObject.put("full_name", repo.getString("path_with_namespace"));
        jsonObject.put("private", StrUtil.equalsIgnoreCase("private", repo.getString("visibility")));
        jsonObject.put("description", repo.getString("description"));
        // 
        jsonObject.put("username", username);
        jsonObject.put("exists", RepositoryController.this.checkRepositoryUrl(null, htmlUrl));
        return jsonObject;
    }).collect(Collectors.toList());
    // 
    PageResultDto<JSONObject> pageResultDto = new PageResultDto<>(page.getPageNumber(), page.getPageSize(), totalCount);
    pageResultDto.setResult(objects);
    return pageResultDto;
}
Also used : PageResultDto(io.jpom.model.PageResultDto) BuildUtil(io.jpom.build.BuildUtil) DefaultSystemLog(cn.jiangzeyin.common.DefaultSystemLog) io.jpom.plugin(io.jpom.plugin) Page(cn.hutool.db.Page) Feature(io.jpom.permission.Feature) ServletUtil(cn.hutool.extra.servlet.ServletUtil) JpomRuntimeException(io.jpom.system.JpomRuntimeException) JsonMessage(cn.jiangzeyin.common.JsonMessage) JSONArray(com.alibaba.fastjson.JSONArray) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpUtil(cn.hutool.http.HttpUtil) HttpResponse(cn.hutool.http.HttpResponse) Map(java.util.Map) GetMapping(org.springframework.web.bind.annotation.GetMapping) URLUtil(cn.hutool.core.util.URLUtil) MethodFeature(io.jpom.permission.MethodFeature) HttpRequest(cn.hutool.http.HttpRequest) PostMapping(org.springframework.web.bind.annotation.PostMapping) RepositoryService(io.jpom.service.dblog.RepositoryService) ClassFeature(io.jpom.permission.ClassFeature) RestController(org.springframework.web.bind.annotation.RestController) Collectors(java.util.stream.Collectors) File(java.io.File) HttpStatus(org.springframework.http.HttpStatus) Tuple(cn.hutool.core.lang.Tuple) StrUtil(cn.hutool.core.util.StrUtil) List(java.util.List) ValidatorItem(cn.jiangzeyin.common.validator.ValidatorItem) RepositoryModel(io.jpom.model.data.RepositoryModel) Const(io.jpom.common.Const) BuildInfoService(io.jpom.service.dblog.BuildInfoService) Convert(cn.hutool.core.convert.Convert) FileUtil(cn.hutool.core.io.FileUtil) JSONObject(com.alibaba.fastjson.JSONObject) Entity(cn.hutool.db.Entity) GitProtocolEnum(io.jpom.model.enums.GitProtocolEnum) BaseServerController(io.jpom.common.BaseServerController) Validator(cn.hutool.core.lang.Validator) Assert(org.springframework.util.Assert) JSONObject(com.alibaba.fastjson.JSONObject) JSONArray(com.alibaba.fastjson.JSONArray) HttpResponse(cn.hutool.http.HttpResponse) PageResultDto(io.jpom.model.PageResultDto)

Example 3 with PageResultDto

use of io.jpom.model.PageResultDto in project Jpom by dromara.

the class RepositoryController method githubRepos.

/**
 * github 仓库
 *
 * @param token 个人令牌
 * @param page  分页
 * @return page
 */
private PageResultDto<JSONObject> githubRepos(String token, Page page) {
    String accept = "application/vnd.github.v3+json";
    HttpRequest request = HttpUtil.createGet("https://api.github.com/user");
    request.header("Authorization", StrUtil.format("token {}", token));
    request.header("Accept", accept);
    HttpResponse httpResponse = request.execute();
    String body = httpResponse.body();
    Assert.state(httpResponse.isOk(), "令牌信息错误:" + body);
    JSONObject userBody = JSONObject.parseObject(body);
    String username = userBody.getString("login");
    // 拉取仓库信息
    HttpRequest httpRequestRepos = HttpUtil.createGet("https://api.github.com/user/repos");
    httpRequestRepos.header("Authorization", StrUtil.format("token {}", token));
    httpRequestRepos.header("Accept", accept);
    HttpResponse reposResponse = httpRequestRepos.form("access_token", token).form("sort", "pushed").form("page", page.getPageNumber()).form("per_page", page.getPageSize()).execute();
    body = reposResponse.body();
    Assert.state(reposResponse.isOk(), "拉取仓库信息错误:" + body);
    JSONArray jsonArray = JSONArray.parseArray(body);
    List<JSONObject> objects = jsonArray.stream().map(o -> {
        JSONObject repo = (JSONObject) o;
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name", repo.getString("name"));
        String cloneUrl = repo.getString("clone_url");
        jsonObject.put("url", cloneUrl);
        jsonObject.put("full_name", repo.getString("full_name"));
        jsonObject.put("description", repo.getString("description"));
        jsonObject.put("private", repo.getBooleanValue("private"));
        // 
        jsonObject.put("username", username);
        jsonObject.put("exists", RepositoryController.this.checkRepositoryUrl(null, cloneUrl));
        return jsonObject;
    }).collect(Collectors.toList());
    // 
    PageResultDto<JSONObject> pageResultDto = new PageResultDto<>(page.getPageNumber(), page.getPageSize(), 1000);
    pageResultDto.setResult(objects);
    return pageResultDto;
}
Also used : HttpRequest(cn.hutool.http.HttpRequest) PageResultDto(io.jpom.model.PageResultDto) BuildUtil(io.jpom.build.BuildUtil) DefaultSystemLog(cn.jiangzeyin.common.DefaultSystemLog) io.jpom.plugin(io.jpom.plugin) Page(cn.hutool.db.Page) Feature(io.jpom.permission.Feature) ServletUtil(cn.hutool.extra.servlet.ServletUtil) JpomRuntimeException(io.jpom.system.JpomRuntimeException) JsonMessage(cn.jiangzeyin.common.JsonMessage) JSONArray(com.alibaba.fastjson.JSONArray) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpUtil(cn.hutool.http.HttpUtil) HttpResponse(cn.hutool.http.HttpResponse) Map(java.util.Map) GetMapping(org.springframework.web.bind.annotation.GetMapping) URLUtil(cn.hutool.core.util.URLUtil) MethodFeature(io.jpom.permission.MethodFeature) HttpRequest(cn.hutool.http.HttpRequest) PostMapping(org.springframework.web.bind.annotation.PostMapping) RepositoryService(io.jpom.service.dblog.RepositoryService) ClassFeature(io.jpom.permission.ClassFeature) RestController(org.springframework.web.bind.annotation.RestController) Collectors(java.util.stream.Collectors) File(java.io.File) HttpStatus(org.springframework.http.HttpStatus) Tuple(cn.hutool.core.lang.Tuple) StrUtil(cn.hutool.core.util.StrUtil) List(java.util.List) ValidatorItem(cn.jiangzeyin.common.validator.ValidatorItem) RepositoryModel(io.jpom.model.data.RepositoryModel) Const(io.jpom.common.Const) BuildInfoService(io.jpom.service.dblog.BuildInfoService) Convert(cn.hutool.core.convert.Convert) FileUtil(cn.hutool.core.io.FileUtil) JSONObject(com.alibaba.fastjson.JSONObject) Entity(cn.hutool.db.Entity) GitProtocolEnum(io.jpom.model.enums.GitProtocolEnum) BaseServerController(io.jpom.common.BaseServerController) Validator(cn.hutool.core.lang.Validator) Assert(org.springframework.util.Assert) JSONObject(com.alibaba.fastjson.JSONObject) JSONArray(com.alibaba.fastjson.JSONArray) HttpResponse(cn.hutool.http.HttpResponse) PageResultDto(io.jpom.model.PageResultDto)

Example 4 with PageResultDto

use of io.jpom.model.PageResultDto in project Jpom by dromara.

the class BaseDbCommonService method listPage.

/**
 * 分页查询
 *
 * @param where 条件
 * @param page  分页
 * @return 结果
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public PageResultDto<T> listPage(Entity where, Page page) {
    if (!DbConfig.getInstance().isInit()) {
        // ignore
        log.error("The database is not initialized, this execution will be ignored:{},{}", this.tClass, this.getClass());
        return PageResultDto.EMPTY;
    }
    where.setTableName(getTableName());
    PageResult<Entity> pageResult;
    Db db = Db.use();
    db.setWrapper((Character) null);
    try {
        pageResult = db.page(where, page);
    } catch (Exception e) {
        throw warpException(e);
    }
    // 
    List<T> list = pageResult.stream().map(entity -> {
        T entityToBean = this.entityToBean(entity, this.tClass);
        this.fillSelectResult(entityToBean);
        return entityToBean;
    }).collect(Collectors.toList());
    PageResultDto<T> pageResultDto = new PageResultDto(pageResult);
    pageResultDto.setResult(list);
    if (pageResultDto.isEmpty() && pageResultDto.getPage() > 1) {
        Assert.state(pageResultDto.getTotal() <= 0, "筛选的分页有问题,当前页码查询不到任何数据");
    }
    return pageResultDto;
}
Also used : PageResultDto(io.jpom.model.PageResultDto) PageResult(cn.hutool.db.PageResult) ExceptionUtil(cn.hutool.core.exceptions.ExceptionUtil) JdbcSQLNonTransientException(org.h2.jdbc.JdbcSQLNonTransientException) BeanUtil(cn.hutool.core.bean.BeanUtil) Page(cn.hutool.db.Page) Order(cn.hutool.db.sql.Order) JpomRuntimeException(io.jpom.system.JpomRuntimeException) LinkedHashMap(java.util.LinkedHashMap) TypeUtil(cn.hutool.core.util.TypeUtil) Map(java.util.Map) PageUtil(cn.hutool.core.util.PageUtil) DbConfig(io.jpom.system.db.DbConfig) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) Db(cn.hutool.db.Db) Consumer(java.util.function.Consumer) CollUtil(cn.hutool.core.collection.CollUtil) StrUtil(cn.hutool.core.util.StrUtil) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Condition(cn.hutool.db.sql.Condition) CopyOptions(cn.hutool.core.bean.copier.CopyOptions) Entity(cn.hutool.db.Entity) Assert(org.springframework.util.Assert) Entity(cn.hutool.db.Entity) Db(cn.hutool.db.Db) JdbcSQLNonTransientException(org.h2.jdbc.JdbcSQLNonTransientException) JpomRuntimeException(io.jpom.system.JpomRuntimeException) PageResultDto(io.jpom.model.PageResultDto)

Aggregations

StrUtil (cn.hutool.core.util.StrUtil)4 Entity (cn.hutool.db.Entity)4 Page (cn.hutool.db.Page)4 PageResultDto (io.jpom.model.PageResultDto)4 JpomRuntimeException (io.jpom.system.JpomRuntimeException)4 List (java.util.List)4 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4 Assert (org.springframework.util.Assert)4 Convert (cn.hutool.core.convert.Convert)3 FileUtil (cn.hutool.core.io.FileUtil)3 Tuple (cn.hutool.core.lang.Tuple)3 Validator (cn.hutool.core.lang.Validator)3 URLUtil (cn.hutool.core.util.URLUtil)3 ServletUtil (cn.hutool.extra.servlet.ServletUtil)3 HttpRequest (cn.hutool.http.HttpRequest)3 HttpResponse (cn.hutool.http.HttpResponse)3 HttpUtil (cn.hutool.http.HttpUtil)3 DefaultSystemLog (cn.jiangzeyin.common.DefaultSystemLog)3 JsonMessage (cn.jiangzeyin.common.JsonMessage)3