Search in sources :

Example 1 with BuildInfoModel

use of io.jpom.model.data.BuildInfoModel in project Jpom by dromara.

the class BuildInfoService method checkReleaseMethod.

/**
 * 判断是否存在 发布关联
 *
 * @param dataId        数据ID
 * @param request       请求对象
 * @param releaseMethod 发布方法
 * @return true 关联
 */
public boolean checkReleaseMethod(String dataId, HttpServletRequest request, BuildReleaseMethod releaseMethod) {
    BuildInfoModel buildInfoModel = new BuildInfoModel();
    String workspaceId = this.getCheckUserWorkspace(request);
    buildInfoModel.setWorkspaceId(workspaceId);
    buildInfoModel.setReleaseMethodDataId(dataId);
    buildInfoModel.setReleaseMethod(releaseMethod.getCode());
    return super.exists(buildInfoModel);
}
Also used : BuildInfoModel(io.jpom.model.data.BuildInfoModel)

Example 2 with BuildInfoModel

use of io.jpom.model.data.BuildInfoModel in project Jpom by dromara.

the class BuildInfoService method updateStatus.

/**
 * 更新状态
 *
 * @param id          ID
 * @param buildStatus to Status
 */
public void updateStatus(String id, BuildStatus buildStatus) {
    BuildInfoModel buildInfoModel = new BuildInfoModel();
    buildInfoModel.setId(id);
    buildInfoModel.setStatus(buildStatus.getCode());
    this.update(buildInfoModel);
}
Also used : BuildInfoModel(io.jpom.model.data.BuildInfoModel)

Example 3 with BuildInfoModel

use of io.jpom.model.data.BuildInfoModel in project Jpom by dromara.

the class BuildTriggerApiController method getStatusData.

private JSONObject getStatusData(String id, String token) {
    JSONObject jsonObject = new JSONObject();
    BuildInfoModel item = buildInfoService.getByKey(id);
    if (item == null) {
        jsonObject.put("msg", "没有对应数据");
        return jsonObject;
    }
    UserModel userModel = BuildTriggerApiController.this.getByUrlToken(token);
    if (userModel == null) {
        jsonObject.put("msg", "对应的用户不存在,触发器已失效");
        return jsonObject;
    }
    // 
    if (!StrUtil.equals(token, item.getTriggerToken())) {
        jsonObject.put("msg", "触发token错误,或者已经失效");
        return jsonObject;
    }
    // 更新字段
    Integer status = item.getStatus();
    BuildStatus buildStatus = BaseEnum.getEnum(BuildStatus.class, status);
    if (buildStatus == null) {
        jsonObject.put("msg", "status code error");
    } else {
        jsonObject.put("msg", buildStatus.getDesc());
        jsonObject.put("statusCode", buildStatus.getCode());
        jsonObject.put("status", buildStatus.name());
    }
    jsonObject.put("buildNumberId", item.getBuildId());
    return jsonObject;
}
Also used : UserModel(io.jpom.model.data.UserModel) JSONObject(com.alibaba.fastjson.JSONObject) BuildStatus(io.jpom.model.enums.BuildStatus) BuildInfoModel(io.jpom.model.data.BuildInfoModel)

Example 4 with BuildInfoModel

use of io.jpom.model.data.BuildInfoModel in project Jpom by dromara.

the class BuildTriggerApiController method triggerBatch.

/**
 * 构建触发器
 * <p>
 * 参数 <code>[
 * {
 * "id":"1",
 * "token":"a",
 * "delay":"0"
 * }
 * ]</code>
 * <p>
 * 响应 <code>[
 * {
 * "id":"1",
 * "token":"a",
 * "delay":"0",
 * "msg":"开始构建",
 * "data":1
 * }
 * ]</code>
 *
 * @return json
 */
@PostMapping(value = ServerOpenApi.BUILD_TRIGGER_BUILD_BATCH, produces = MediaType.APPLICATION_JSON_VALUE)
public String triggerBatch() {
    try {
        String body = ServletUtil.getBody(getRequest());
        JSONArray jsonArray = JSONArray.parseArray(body);
        List<Object> collect = jsonArray.stream().peek(o -> {
            JSONObject jsonObject = (JSONObject) o;
            String id = jsonObject.getString("id");
            String token = jsonObject.getString("token");
            Integer delay = jsonObject.getInteger("delay");
            String buildRemark = jsonObject.getString("buildRemark");
            BuildInfoModel item = buildInfoService.getByKey(id);
            if (item == null) {
                jsonObject.put("msg", "没有对应数据");
                return;
            }
            UserModel userModel = BuildTriggerApiController.this.getByUrlToken(token);
            if (userModel == null) {
                jsonObject.put("msg", "对应的用户不存在,触发器已失效");
                return;
            }
            // 
            if (!StrUtil.equals(token, item.getTriggerToken())) {
                jsonObject.put("msg", "触发token错误,或者已经失效");
                return;
            }
            // 更新字段
            String updateItemErrorMsg = this.updateItem(jsonObject);
            if (updateItemErrorMsg != null) {
                jsonObject.put("msg", updateItemErrorMsg);
                return;
            }
            BaseServerController.resetInfo(userModel);
            // 
            JsonMessage<Integer> start = buildExecuteService.start(id, userModel, delay, 1, buildRemark);
            jsonObject.put("msg", start.getMsg());
            jsonObject.put("buildId", start.getData());
        }).collect(Collectors.toList());
        return JsonMessage.getString(200, "触发成功", collect);
    } catch (Exception e) {
        DefaultSystemLog.getLog().error("构建触发批量触发异常", e);
        return JsonMessage.getString(500, "触发异常", e.getMessage());
    }
}
Also used : ObjectUtil(cn.hutool.core.util.ObjectUtil) ServerOpenApi(io.jpom.common.ServerOpenApi) DefaultSystemLog(cn.jiangzeyin.common.DefaultSystemLog) ServletUtil(cn.hutool.extra.servlet.ServletUtil) JsonMessage(cn.jiangzeyin.common.JsonMessage) JSONArray(com.alibaba.fastjson.JSONArray) BuildInfoTriggerController(io.jpom.controller.build.BuildInfoTriggerController) BaseEnum(io.jpom.model.BaseEnum) RegexPool(cn.hutool.core.lang.RegexPool) MediaType(org.springframework.http.MediaType) Collectors(java.util.stream.Collectors) BaseJpomController(io.jpom.common.BaseJpomController) StringUtils(org.h2.util.StringUtils) StrUtil(cn.hutool.core.util.StrUtil) List(java.util.List) ValidatorItem(cn.jiangzeyin.common.validator.ValidatorItem) BuildInfoService(io.jpom.service.dblog.BuildInfoService) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) Convert(cn.hutool.core.convert.Convert) JSONObject(com.alibaba.fastjson.JSONObject) Entity(cn.hutool.db.Entity) BuildInfoModel(io.jpom.model.data.BuildInfoModel) NotLogin(io.jpom.common.interceptor.NotLogin) BuildExecuteService(io.jpom.build.BuildExecuteService) UserModel(io.jpom.model.data.UserModel) BuildStatus(io.jpom.model.enums.BuildStatus) UserService(io.jpom.service.user.UserService) BaseServerController(io.jpom.common.BaseServerController) Validator(cn.hutool.core.lang.Validator) Assert(org.springframework.util.Assert) UserModel(io.jpom.model.data.UserModel) JSONObject(com.alibaba.fastjson.JSONObject) JsonMessage(cn.jiangzeyin.common.JsonMessage) JSONArray(com.alibaba.fastjson.JSONArray) JSONObject(com.alibaba.fastjson.JSONObject) BuildInfoModel(io.jpom.model.data.BuildInfoModel)

Example 5 with BuildInfoModel

use of io.jpom.model.data.BuildInfoModel in project Jpom by dromara.

the class BuildInfoController method getBuildList.

/**
 * load build list with params
 *
 * @return json
 */
@RequestMapping(value = "/build/list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.LIST)
public String getBuildList() {
    // load list with page
    PageResultDto<BuildInfoModel> page = buildInfoService.listPage(getRequest());
    page.each(buildInfoModel -> {
        // 获取源码目录是否存在
        File source = BuildUtil.getSourceById(buildInfoModel.getId());
        buildInfoModel.setSourceDirExist(FileUtil.exist(source));
    });
    return JsonMessage.getString(200, "", page);
}
Also used : File(java.io.File) BuildInfoModel(io.jpom.model.data.BuildInfoModel) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature)

Aggregations

BuildInfoModel (io.jpom.model.data.BuildInfoModel)22 ClassFeature (io.jpom.permission.ClassFeature)12 Feature (io.jpom.permission.Feature)12 MethodFeature (io.jpom.permission.MethodFeature)12 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 File (java.io.File)7 UserModel (io.jpom.model.data.UserModel)5 BuildHistoryLog (io.jpom.model.log.BuildHistoryLog)5 JSONObject (com.alibaba.fastjson.JSONObject)4 JsonMessage (cn.jiangzeyin.common.JsonMessage)3 BuildStatus (io.jpom.model.enums.BuildStatus)3 RepositoryModel (io.jpom.model.data.RepositoryModel)2 Convert (cn.hutool.core.convert.Convert)1 RegexPool (cn.hutool.core.lang.RegexPool)1 Validator (cn.hutool.core.lang.Validator)1 ObjectUtil (cn.hutool.core.util.ObjectUtil)1 StrUtil (cn.hutool.core.util.StrUtil)1 Entity (cn.hutool.db.Entity)1 ServletUtil (cn.hutool.extra.servlet.ServletUtil)1 DefaultSystemLog (cn.jiangzeyin.common.DefaultSystemLog)1