use of com.rebuild.core.service.DataSpecificationException in project rebuild by getrebuild.
the class BaseConfigurationService method delete.
@Override
public int delete(ID recordId) {
ID locked = hasLock() ? CommonsLock.getLockedUser(recordId) : null;
if (locked != null && !locked.equals(UserContextHolder.getUser())) {
throw new DataSpecificationException(Language.L("操作失败 (已被锁定)"));
}
throwIfNotSelf(recordId);
cleanCache(recordId);
return super.delete(recordId);
}
use of com.rebuild.core.service.DataSpecificationException in project rebuild by getrebuild.
the class BaseConfigurationService method update.
@Override
public Record update(Record record) {
ID locked = hasLock() ? CommonsLock.getLockedUser(record.getPrimary()) : null;
if (locked != null && !locked.equals(UserContextHolder.getUser())) {
throw new DataSpecificationException(Language.L("操作失败 (已被锁定)"));
}
throwIfNotSelf(record.getPrimary());
cleanCache(record.getPrimary());
return super.update(record);
}
use of com.rebuild.core.service.DataSpecificationException in project rebuild by getrebuild.
the class SignUpController method signupConfirm.
@PostMapping("signup-confirm")
public RespBody signupConfirm(HttpServletRequest request) {
JSONObject data = (JSONObject) ServletUtils.getRequestJson(request);
String email = data.getString("email");
String vcode = data.getString("vcode");
if (!VerfiyCode.verfiy(email, vcode, true)) {
return RespBody.errorl("无效验证码");
}
String loginName = data.getString("loginName");
String fullName = data.getString("fullName");
String passwd = CodecUtils.randomCode(8) + "!8";
Record userNew = EntityHelper.forNew(EntityHelper.User, UserService.SYSTEM_USER);
userNew.setString("email", email);
userNew.setString("loginName", loginName);
userNew.setString("fullName", fullName);
userNew.setString("password", passwd);
try {
Application.getBean(UserService.class).txSignUp(userNew);
// 通知用户
String homeUrl = RebuildConfiguration.getHomeUrl();
String title = Language.L("管理员正在审核你的注册信息");
String content = Language.L("%s 欢迎注册!以下是你的注册信息,请妥善保管。 [][] 登录账号 : **%s** [] 登录密码 : **%s** [] 登录地址 : [%s](%s) [][] 目前你还无法登录系统,因为系统管理员正在审核你的注册信息。完成后会通过邮件通知你,请耐心等待。", fullName, loginName, passwd, homeUrl, homeUrl);
SMSender.sendMail(email, title, content);
return RespBody.ok();
} catch (DataSpecificationException ex) {
return RespBody.error(ex.getLocalizedMessage());
}
}
use of com.rebuild.core.service.DataSpecificationException in project rebuild by getrebuild.
the class GeneralOperatingController method save.
@PostMapping("record-save")
public JSONAware save(HttpServletRequest request) {
final ID user = getRequestUser(request);
final JSON formJson = ServletUtils.getRequestJson(request);
final Object details = ((JSONObject) formJson).remove(GeneralEntityService.HAS_DETAILS);
Record record;
try {
record = EntityHelper.parse((JSONObject) formJson, user);
} catch (DataSpecificationException known) {
log.warn(">>>>> {}", known.getLocalizedMessage());
return RespBody.error(known.getLocalizedMessage());
}
// 非业务实体(兼容所有类型的实体)
if (!MetadataHelper.isBusinessEntity(record.getEntity())) {
return CommonOperatingController.saveRecord(record);
}
// 明细
List<Record> detailsList = new ArrayList<>();
if (details != null) {
try {
for (Object d : (JSONArray) details) {
Record detail = EntityHelper.parse((JSONObject) d, user);
detailsList.add(detail);
}
} catch (DataSpecificationException known) {
log.warn(">>>>> {}", known.getLocalizedMessage());
return RespBody.error(known.getLocalizedMessage());
}
}
final EntityService ies = Application.getEntityService(record.getEntity().getEntityCode());
// 检查重复值
List<Record> repeated = ies.getAndCheckRepeated(record, 20);
if (!repeated.isEmpty()) {
return new RespBody(DefinedException.CODE_RECORDS_REPEATED, Language.L("存在重复记录"), buildRepeatedData(repeated));
}
if (!detailsList.isEmpty()) {
record.setObjectValue(GeneralEntityService.HAS_DETAILS, detailsList);
GeneralEntityServiceContextHolder.setRepeatedCheckMode(GeneralEntityServiceContextHolder.RCM_CHECK_DETAILS);
}
try {
record = ies.createOrUpdate(record);
} catch (RepeatedRecordsException know) {
return new RespBody(DefinedException.CODE_RECORDS_REPEATED, Language.L("存在重复记录"), buildRepeatedData(know.getRepeatedRecords()));
} catch (AccessDeniedException | DataSpecificationException known) {
log.warn(">>>>> {}", known.getLocalizedMessage());
return RespBody.error(known.getLocalizedMessage());
} catch (GenericJdbcException ex) {
String known = KnownExceptionConverter.convert2ErrorMsg(ex);
if (known != null)
return RespBody.error(known);
log.error(null, ex);
return RespBody.error(ex.getLocalizedMessage());
} finally {
// 确保清除
GeneralEntityServiceContextHolder.getRepeatedCheckModeOnce();
}
JSONObject ret = new JSONObject();
ret.put("id", record.getPrimary());
// 单字段修改立即返回新值
boolean viaSingle = getBoolParameter(request, "single");
if (viaSingle) {
for (String field : record.getAvailableFields()) {
Field fieldMeta = record.getEntity().getField(field);
if (MetadataHelper.isCommonsField(field) || fieldMeta.getType() == FieldType.PRIMARY) {
continue;
}
Object newValue = FormsBuilder.instance.wrapFieldValue(record, EasyMetaFactory.valueOf(fieldMeta), null);
ret.put(field, newValue);
}
}
return ret;
}
use of com.rebuild.core.service.DataSpecificationException in project rebuild by getrebuild.
the class GeneralOperatingController method delete.
@PostMapping("record-delete")
public JSONAware delete(HttpServletRequest request) {
final ID user = getRequestUser(request);
final ID[] records = parseIdList(request);
if (records.length == 0) {
return RespBody.errorl("没有要删除的记录");
}
final ID firstId = records[0];
final Entity entity = MetadataHelper.getEntity(firstId.getEntityCode());
// 兼容所有类型的实体
if (!MetadataHelper.isBusinessEntity(entity)) {
return CommonOperatingController.deleteRecord(firstId);
}
final EntityService ies = Application.getEntityService(entity.getEntityCode());
String[] cascades = parseCascades(request);
int affected;
try {
if (records.length == 1) {
affected = ies.delete(firstId, cascades);
} else {
BulkContext context = new BulkContext(user, BizzPermission.DELETE, null, cascades, records);
affected = ies.bulk(context);
}
} catch (AccessDeniedException | DataSpecificationException known) {
log.warn(">>>>> {}", known.getLocalizedMessage());
return RespBody.error(known.getLocalizedMessage());
}
return JSONUtils.toJSONObject(new String[] { "deleted", "requests" }, new Object[] { affected, records.length });
}
Aggregations