Search in sources :

Example 6 with DataSpecificationException

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);
}
Also used : DataSpecificationException(com.rebuild.core.service.DataSpecificationException) ID(cn.devezhao.persist4j.engine.ID)

Example 7 with DataSpecificationException

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);
}
Also used : DataSpecificationException(com.rebuild.core.service.DataSpecificationException) ID(cn.devezhao.persist4j.engine.ID)

Example 8 with DataSpecificationException

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());
    }
}
Also used : 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 9 with DataSpecificationException

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;
}
Also used : AccessDeniedException(cn.devezhao.bizz.security.AccessDeniedException) JSONArray(com.alibaba.fastjson.JSONArray) JSON(com.alibaba.fastjson.JSON) DataSpecificationException(com.rebuild.core.service.DataSpecificationException) RespBody(com.rebuild.api.RespBody) Field(cn.devezhao.persist4j.Field) JSONObject(com.alibaba.fastjson.JSONObject) JSONObject(com.alibaba.fastjson.JSONObject) Record(cn.devezhao.persist4j.Record) ID(cn.devezhao.persist4j.engine.ID) GenericJdbcException(cn.devezhao.persist4j.exception.jdbc.GenericJdbcException) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 10 with DataSpecificationException

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 });
}
Also used : Entity(cn.devezhao.persist4j.Entity) AccessDeniedException(cn.devezhao.bizz.security.AccessDeniedException) DataSpecificationException(com.rebuild.core.service.DataSpecificationException) ID(cn.devezhao.persist4j.engine.ID) PostMapping(org.springframework.web.bind.annotation.PostMapping)

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