Search in sources :

Example 11 with DataSpecificationException

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

the class CommonOperatingController method save.

@PostMapping("common-save")
public JSONAware save(HttpServletRequest request) {
    final JSON formJson = ServletUtils.getRequestJson(request);
    Record record;
    try {
        record = EntityHelper.parse((JSONObject) formJson, getRequestUser(request));
    } catch (DataSpecificationException known) {
        log.warn(">>>>> {}", known.getLocalizedMessage());
        return RespBody.error(known.getLocalizedMessage());
    }
    return saveRecord(record);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSON(com.alibaba.fastjson.JSON) Record(cn.devezhao.persist4j.Record) DataSpecificationException(com.rebuild.core.service.DataSpecificationException) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 12 with DataSpecificationException

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

the class ProjectTaskService method update.

@Override
public Record update(Record record) {
    final ID user = UserContextHolder.getUser();
    checkModifications(user, record.getPrimary());
    // 自动完成
    int newFlowStatus = applyFlowStatus(record);
    if (newFlowStatus == ProjectPlanConfigService.FLOW_STATUS_END) {
        record.setDate("endTime", CalendarUtils.now());
    } else if (record.hasValue("status")) {
        int status = record.getInt("status");
        // 处理完成时间
        if (status == 0) {
            record.setNull("endTime");
            record.setInt("seq", getSeqInStatus(record.getPrimary(), false));
        } else {
            // 检查工作流
            Object[] flowStatus = Application.getQueryFactory().uniqueNoFilter(record.getPrimary(), "projectPlanId.flowStatus");
            if ((int) flowStatus[0] == ProjectPlanConfigService.FLOW_STATUS_PROCESSING) {
                throw new DataSpecificationException(Language.L("该任务面板不可完成任务"));
            }
            record.setDate("endTime", CalendarUtils.now());
            record.setInt("seq", getSeqInStatus(record.getPrimary(), true));
        }
    } else if (record.hasValue("seq")) {
        int seq = record.getInt("seq");
        if (seq == SEQ_ATLAST) {
            record.setInt("seq", getSeqInStatus(record.getPrimary(), true));
        }
    }
    record = super.update(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)

Example 13 with DataSpecificationException

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

the class BulkDelete method exec.

@Override
public Integer exec() {
    final ID[] records = prepareRecords();
    this.setTotal(records.length);
    for (ID id : records) {
        if (Application.getPrivilegesManager().allowDelete(context.getOpUser(), id)) {
            try {
                ges.delete(id, context.getCascades());
                this.addSucceeded();
            } catch (DataSpecificationException ex) {
                log.warn("Cannot delete `{}` because : {}", id, ex.getLocalizedMessage());
            }
        } else {
            log.warn("No have privileges to DELETE : {} < {}", id, context.getOpUser());
        }
        this.addCompleted();
    }
    return getSucceeded();
}
Also used : DataSpecificationException(com.rebuild.core.service.DataSpecificationException) ID(cn.devezhao.persist4j.engine.ID)

Example 14 with DataSpecificationException

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

the class AttachmentFolderService method delete.

@Override
public int delete(ID recordId) {
    Object inFolder = Application.createQueryNoFilter("select inFolder from Attachment where inFolder = ?").setParameter(1, recordId).unique();
    if (inFolder != null) {
        throw new DataSpecificationException(Language.L("目录内有文件不能删除"));
    }
    Object parent = Application.createQueryNoFilter("select parent from AttachmentFolder where parent = ?").setParameter(1, recordId).unique();
    if (parent != null) {
        throw new DataSpecificationException(Language.L("目录下有子目录不能删除"));
    }
    ID user = UserContextHolder.getUser();
    if (!UserHelper.isAdmin(user)) {
        Object[] createdBy = Application.createQueryNoFilter("select createdBy from AttachmentFolder where folderId = ?").setParameter(1, recordId).unique();
        if (!user.equals(createdBy[0])) {
            throw new DataSpecificationException(Language.L("无权删除他人目录"));
        }
    }
    return super.delete(recordId);
}
Also used : DataSpecificationException(com.rebuild.core.service.DataSpecificationException) ID(cn.devezhao.persist4j.engine.ID)

Example 15 with DataSpecificationException

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

the class ApprovalController method doApprove.

@PostMapping("approve")
public RespBody doApprove(HttpServletRequest request, @IdParam(name = "record") ID recordId) {
    final ID approver = getRequestUser(request);
    final int state = getIntParameter(request, "state", ApprovalState.REJECTED.getState());
    JSONObject post = (JSONObject) ServletUtils.getRequestJson(request);
    JSONObject selectUsers = post.getJSONObject("selectUsers");
    String remark = post.getString("remark");
    String useGroup = post.getString("useGroup");
    // 可编辑字段
    JSONObject aformData = post.getJSONObject("aformData");
    Record addedRecord = null;
    // 没有或无更新
    if (aformData != null && aformData.size() > 1) {
        try {
            addedRecord = EntityHelper.parse(aformData, getRequestUser(request));
        } catch (DataSpecificationException known) {
            log.warn(">>>>> {}", known.getLocalizedMessage());
            return RespBody.error(known.getLocalizedMessage());
        }
    }
    try {
        new ApprovalProcessor(recordId).approve(approver, (ApprovalState) ApprovalState.valueOf(state), remark, selectUsers, addedRecord, useGroup);
        return RespBody.ok();
    } catch (DataSpecificationNoRollbackException ex) {
        return RespBody.error(ex.getLocalizedMessage(), DefinedException.CODE_APPROVE_WARN);
    } catch (ApprovalException ex) {
        return RespBody.error(ex.getLocalizedMessage());
    }
}
Also used : DataSpecificationNoRollbackException(com.rebuild.core.service.DataSpecificationNoRollbackException) JSONObject(com.alibaba.fastjson.JSONObject) Record(cn.devezhao.persist4j.Record) DataSpecificationException(com.rebuild.core.service.DataSpecificationException) ID(cn.devezhao.persist4j.engine.ID)

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