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