Search in sources :

Example 1 with RecycleStore

use of com.rebuild.core.service.general.recyclebin.RecycleStore in project rebuild by getrebuild.

the class GeneralEntityService method delete.

@Override
public int delete(ID record, String[] cascades) {
    final ID currentUser = UserContextHolder.getUser();
    final RecycleStore recycleBin = useRecycleStore(record);
    this.deleteInternal(record);
    int affected = 1;
    Map<String, Set<ID>> recordsOfCascaded = getCascadedRecords(record, cascades, BizzPermission.DELETE);
    for (Map.Entry<String, Set<ID>> e : recordsOfCascaded.entrySet()) {
        if (log.isDebugEnabled()) {
            log.debug("Cascade delete - " + e.getKey() + " > " + e.getValue());
        }
        for (ID id : e.getValue()) {
            if (Application.getPrivilegesManager().allowDelete(currentUser, id)) {
                if (recycleBin != null)
                    recycleBin.add(id, record);
                int deleted = 0;
                try {
                    deleted = this.deleteInternal(id);
                } catch (DataSpecificationException ex) {
                    log.warn("Cannot delete : " + id + " Ex : " + ex);
                } finally {
                    if (deleted > 0) {
                        affected++;
                    } else if (recycleBin != null) {
                        // If not delete
                        recycleBin.removeLast();
                    }
                }
            } else {
                log.warn("No have privileges to DELETE : " + currentUser + " > " + id);
            }
        }
    }
    if (recycleBin != null)
        recycleBin.store();
    return affected;
}
Also used : RecycleStore(com.rebuild.core.service.general.recyclebin.RecycleStore) DataSpecificationException(com.rebuild.core.service.DataSpecificationException) ID(cn.devezhao.persist4j.engine.ID)

Example 2 with RecycleStore

use of com.rebuild.core.service.general.recyclebin.RecycleStore in project rebuild by getrebuild.

the class ProjectTaskService method delete.

@Override
public int delete(ID taskId) {
    final ID user = UserContextHolder.getUser();
    if (!ProjectHelper.isManageable(taskId, user))
        throw new OperationDeniedException();
    // 先删评论
    Object[][] comments = Application.createQueryNoFilter("select commentId from ProjectTaskComment where taskId = ?").setParameter(1, taskId).array();
    for (Object[] c : comments) {
        Application.getBean(ProjectCommentService.class).delete((ID) c[0]);
    }
    // 只有任务本身可以恢复
    final RecycleStore recycleBin = useRecycleStore(taskId);
    int d = super.delete(taskId);
    ProjectManager.instance.clean(taskId);
    if (recycleBin != null)
        recycleBin.store();
    return d;
}
Also used : OperationDeniedException(com.rebuild.core.privileges.OperationDeniedException) RecycleStore(com.rebuild.core.service.general.recyclebin.RecycleStore) ID(cn.devezhao.persist4j.engine.ID)

Example 3 with RecycleStore

use of com.rebuild.core.service.general.recyclebin.RecycleStore in project rebuild by getrebuild.

the class ObservableService method useRecycleStore.

/**
 * 使用回收站
 *
 * @param recordId
 * @return 返回 null 表示没开启
 */
protected RecycleStore useRecycleStore(ID recordId) {
    final ID currentUser = UserContextHolder.getUser();
    RecycleStore recycleBin = null;
    if (RecycleBinCleanerJob.isEnableRecycleBin()) {
        recycleBin = new RecycleStore(currentUser);
    } else {
        log.warn("RecycleBin inactivated! DELETE {} by {}", recordId, currentUser);
    }
    if (recycleBin != null)
        recycleBin.add(recordId);
    return recycleBin;
}
Also used : RecycleStore(com.rebuild.core.service.general.recyclebin.RecycleStore) ID(cn.devezhao.persist4j.engine.ID)

Example 4 with RecycleStore

use of com.rebuild.core.service.general.recyclebin.RecycleStore in project rebuild by getrebuild.

the class FeedsService method delete.

@Override
public int delete(ID recordId) {
    // 先删评论
    Object[][] comments = Application.createQueryNoFilter("select commentId from FeedsComment where feedsId = ?").setParameter(1, recordId).array();
    for (Object[] c : comments) {
        Application.getBean(FeedsCommentService.class).delete((ID) c[0]);
    }
    // 只有动态本身可以恢复
    final RecycleStore recycleBin = useRecycleStore(recordId);
    int d = super.delete(recordId);
    if (recycleBin != null)
        recycleBin.store();
    return d;
}
Also used : RecycleStore(com.rebuild.core.service.general.recyclebin.RecycleStore)

Aggregations

RecycleStore (com.rebuild.core.service.general.recyclebin.RecycleStore)4 ID (cn.devezhao.persist4j.engine.ID)3 OperationDeniedException (com.rebuild.core.privileges.OperationDeniedException)1 DataSpecificationException (com.rebuild.core.service.DataSpecificationException)1