Search in sources :

Example 16 with DataSpecificationException

use of com.rebuild.core.service.DataSpecificationException in project rebuild by getrebuild.

the class UserSettingsController method savePasswd.

private RespBody savePasswd(ID user, String password) {
    Record record = EntityHelper.forUpdate(user, user);
    record.setString("password", password);
    try {
        Application.getBean(UserService.class).update(record);
    } catch (DataSpecificationException ex) {
        return RespBody.error(ex.getMessage());
    }
    return RespBody.ok();
}
Also used : UserService(com.rebuild.core.privileges.UserService) Record(cn.devezhao.persist4j.Record) DataSpecificationException(com.rebuild.core.service.DataSpecificationException)

Example 17 with DataSpecificationException

use of com.rebuild.core.service.DataSpecificationException in project rebuild by getrebuild.

the class LoginController method userConfirmPasswd.

@PostMapping("user-confirm-passwd")
public RespBody userConfirmPasswd(HttpServletRequest request) {
    JSONObject data = (JSONObject) ServletUtils.getRequestJson(request);
    String newpwd = data.getString("newpwd");
    String email = data.getString("email");
    String vcode = data.getString("vcode");
    if (!VerfiyCode.verfiy(email, vcode, true)) {
        return RespBody.errorl("无效验证码");
    }
    User user = Application.getUserStore().getUserByEmail(email);
    Record record = EntityHelper.forUpdate(user.getId(), user.getId());
    record.setString("password", newpwd);
    try {
        UserContextHolder.setUser(user.getId());
        Application.getBean(UserService.class).update(record);
        VerfiyCode.clean(email);
        return RespBody.ok();
    } catch (DataSpecificationException ex) {
        return RespBody.error(ex.getLocalizedMessage());
    } finally {
        UserContextHolder.clear();
    }
}
Also used : User(com.rebuild.core.privileges.bizz.User) JSONObject(com.alibaba.fastjson.JSONObject) UserService(com.rebuild.core.privileges.UserService) Record(cn.devezhao.persist4j.Record) DataSpecificationException(com.rebuild.core.service.DataSpecificationException) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 18 with DataSpecificationException

use of com.rebuild.core.service.DataSpecificationException in project rebuild by getrebuild.

the class ProjectTaskService method create.

@Override
public Record create(Record record) {
    final ID user = UserContextHolder.getUser();
    checkModifications(user, record.getID("projectId"));
    ID projectId = record.getID("projectId");
    ID projectPlanId = record.getID("projectPlanId");
    ConfigBean p = ProjectManager.instance.getPlanOfProject(projectPlanId, projectId);
    if (p.getInteger("flowStatus") == ProjectPlanConfigService.FLOW_STATUS_PROCESSING) {
        throw new DataSpecificationException(Language.L("该任务面板不可新建任务"));
    }
    record.setLong("taskNumber", getNextTaskNumber(projectId));
    applyFlowStatus(record);
    record.setInt("seq", getNextSeqViaMidValue(projectPlanId));
    record = super.create(record);
    if (record.hasValue("executor", false)) {
        sendNotification(record.getPrimary());
    }
    return record;
}
Also used : DataSpecificationException(com.rebuild.core.service.DataSpecificationException) ID(cn.devezhao.persist4j.engine.ID) ConfigBean(com.rebuild.core.configuration.ConfigBean)

Example 19 with DataSpecificationException

use of com.rebuild.core.service.DataSpecificationException in project rebuild by getrebuild.

the class BaseTaskService method checkModifications.

/**
 * 是否成员;是否已归档
 *
 * @param user
 * @param taskOrProject
 * @return
 */
protected boolean checkModifications(ID user, ID taskOrProject) {
    if (user == null)
        user = UserContextHolder.getUser();
    Assert.notNull(taskOrProject, "taskOrProject");
    ConfigBean c = taskOrProject.getEntityCode() == EntityHelper.ProjectTask ? ProjectManager.instance.getProjectByX(taskOrProject, null) : ProjectManager.instance.getProject(taskOrProject, null);
    if (c == null || !c.get("members", Set.class).contains(user)) {
        throw new DataSpecificationException(Language.L("非项目成员禁止操作"));
    }
    if (c.getInteger("status") == ProjectManager.STATUS_ARCHIVED) {
        throw new DataSpecificationException(Language.L("已归档项目禁止操作"));
    }
    return true;
}
Also used : Set(java.util.Set) DataSpecificationException(com.rebuild.core.service.DataSpecificationException) ConfigBean(com.rebuild.core.configuration.ConfigBean)

Example 20 with DataSpecificationException

use of com.rebuild.core.service.DataSpecificationException in project rebuild by getrebuild.

the class ApiGateway method api.

@CrossOrigin
@RequestMapping("/gw/api/**")
public void api(HttpServletRequest request, HttpServletResponse response) {
    String path = request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE).toString();
    String bestMatchingPattern = request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE).toString();
    final String apiName = new AntPathMatcher().extractPathWithinPattern(bestMatchingPattern, path);
    final Date reuqestTime = CalendarUtils.now();
    final String remoteIp = ServletUtils.getRemoteAddr(request);
    final String requestId = UUID.randomUUID().toString();
    response.addHeader("X-RB-Server", ServerStatus.STARTUP_ONCE + "/" + Application.BUILD);
    response.setHeader("X-Request-Id", requestId);
    if (RRL.overLimitWhenIncremented("ip:" + remoteIp)) {
        JSON error = formatFailure("Request frequency exceeded", ApiInvokeException.ERR_FREQUENCY);
        log.error("{} : {}", requestId, error.toJSONString());
        ServletUtils.writeJson(response, error.toJSONString());
        return;
    }
    int errorCode;
    String errorMsg;
    ApiContext context = null;
    try {
        final BaseApi api = createApi(apiName);
        context = verfiy(request, api);
        UserContextHolder.setReqip(remoteIp);
        UserContextHolder.setUser(context.getBindUser());
        JSON result = api.execute(context);
        logRequestAsync(reuqestTime, remoteIp, requestId, apiName, context, result);
        ServletUtils.writeJson(response, result.toJSONString());
        return;
    } catch (ApiInvokeException ex) {
        errorCode = ex.getErrorCode();
        errorMsg = ex.getErrorMsg();
    } catch (DataSpecificationException ex) {
        errorCode = ApiInvokeException.ERR_DATASPEC;
        errorMsg = ex.getLocalizedMessage();
    } catch (Throwable ex) {
        errorCode = Controller.CODE_SERV_ERROR;
        errorMsg = ex.getLocalizedMessage();
    } finally {
        UserContextHolder.clear();
    }
    JSON error = formatFailure(StringUtils.defaultIfBlank(errorMsg, "Server Internal Error"), errorCode);
    try {
        logRequestAsync(reuqestTime, remoteIp, requestId, apiName, context, error);
    } catch (Exception ignored) {
    }
    log.error("{} : {}", requestId, error.toJSONString());
    ServletUtils.writeJson(response, error.toJSONString());
}
Also used : JSON(com.alibaba.fastjson.JSON) DataSpecificationException(com.rebuild.core.service.DataSpecificationException) AntPathMatcher(org.springframework.util.AntPathMatcher) DataSpecificationException(com.rebuild.core.service.DataSpecificationException) CrossOrigin(org.springframework.web.bind.annotation.CrossOrigin) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

DataSpecificationException (com.rebuild.core.service.DataSpecificationException)20 ID (cn.devezhao.persist4j.engine.ID)13 Record (cn.devezhao.persist4j.Record)7 JSONObject (com.alibaba.fastjson.JSONObject)7 PostMapping (org.springframework.web.bind.annotation.PostMapping)5 JSON (com.alibaba.fastjson.JSON)3 UserService (com.rebuild.core.privileges.UserService)3 AccessDeniedException (cn.devezhao.bizz.security.AccessDeniedException)2 Field (cn.devezhao.persist4j.Field)2 JSONArray (com.alibaba.fastjson.JSONArray)2 ConfigBean (com.rebuild.core.configuration.ConfigBean)2 EasyField (com.rebuild.core.metadata.easymeta.EasyField)2 Entity (cn.devezhao.persist4j.Entity)1 GenericJdbcException (cn.devezhao.persist4j.exception.jdbc.GenericJdbcException)1 RespBody (com.rebuild.api.RespBody)1 Department (com.rebuild.core.privileges.bizz.Department)1 User (com.rebuild.core.privileges.bizz.User)1 DataSpecificationNoRollbackException (com.rebuild.core.service.DataSpecificationNoRollbackException)1 NoRecordFoundException (com.rebuild.core.service.NoRecordFoundException)1 ApprovalState (com.rebuild.core.service.approval.ApprovalState)1