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();
}
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();
}
}
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;
}
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;
}
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());
}
Aggregations