package cn.axzo.workflow.core.engine.cmd;

import org.flowable.common.engine.impl.interceptor.Command;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.common.engine.impl.persistence.entity.PropertyEntity;
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.flowable.engine.impl.util.CommandContextUtil;

import java.util.Objects;

/**
 * 操作 ACT_GE_PROPERTY 表的删除指定属性的命令
 *
 * @author wangli
 * @since 2024-09-30 15:15
 */
public class CustomClearPropertyCmd implements Command<Void> {
    private final String propertyName;

    public CustomClearPropertyCmd(String propertyName) {
        this.propertyName = propertyName;
    }

    @Override
    public Void execute(CommandContext commandContext) {
        ProcessEngineConfigurationImpl processEngineConfiguration =
                CommandContextUtil.getProcessEngineConfiguration(commandContext);
        PropertyEntity entity = processEngineConfiguration.getPropertyEntityManager().findById(propertyName);
        if (Objects.nonNull(entity)) {
            processEngineConfiguration.getPropertyEntityManager().delete(entity.getId());
        }
        return null;
    }
}
