StepOwnerTypeEnum.java

package com.mycim.valueobject.consts;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Qiansheng.Wang
 * @since 2020-01-03
 */
public enum StepOwnerTypeEnum {

    /**
     * 步骤的拥有者类型 - 用户
     */
    USER("User"),
    /**
     * 步骤的拥有者类型 - 用户组
     */
    USER_GROUP("User Group"),
    /**
     * 步骤的拥有者类型 - 角色
     */
    ROLE("Role"),
    /**
     * 步骤的拥有者类型 - 创建者本人
     */
    CREATOR("Creator"),
    /**
     * 步骤的拥有者类型 - 创建者的主管
     */
    CREATOR_SUPERVISOR("Creator's Supervisor"),
    /**
     * 步骤的拥有者类型 - 动态签名
     */
    DYNAMIC_SIGNER("Dynamic Signer"),
    /**
     * 步骤的拥有者类型 - 动态签名组
     */
    DYNAMIC_STATION_USERGROUP("PE/EE");

    private String description;

    private StepOwnerTypeEnum(String desc) {
        this.description = desc;
    }

    public static boolean isUser(String stepOwnerType) {
        return StepOwnerTypeEnum.USER.toString().equals(stepOwnerType);
    }

    public static boolean isUserGroup(String stepOwnerType) {
        return StepOwnerTypeEnum.USER_GROUP.toString().equals(stepOwnerType);
    }

    public static boolean isRole(String stepOwnerType) {
        return StepOwnerTypeEnum.ROLE.toString().equals(stepOwnerType);
    }

    public static boolean isCreator(String ownerType) {
        return CREATOR.toString().equals(ownerType);
    }

    public static boolean isCreatorSupervisor(String ownerType) {
        return CREATOR_SUPERVISOR.toString().equals(ownerType);
    }

    public static boolean isDynamicSigner(String ownerType) {
        return DYNAMIC_SIGNER.toString().equals(ownerType);
    }

    public static boolean isNeedStepOwnerId(String stepOwnerType) {
        return isUser(stepOwnerType) || isUserGroup(stepOwnerType) || isRole(stepOwnerType);
    }

    /**
     * Convert the {@code OwnerTypeEnum} to {@code List<Map<String, String>>}
     * <p>
     * Key is element string, value is element description
     *
     * @return {"key": "element.toString", "value": "element.getDescription"}
     */
    public static List<Map<String, String>> toMapList() {
        List<Map<String, String>> list = new ArrayList<>();

        for (StepOwnerTypeEnum element : StepOwnerTypeEnum.values()) {
            if (element.equals(CREATOR_SUPERVISOR) || element.equals(DYNAMIC_SIGNER)) {
                continue;
            }

            Map<String, String> map = new HashMap<>();
            map.put("key", element.toString());
            map.put("value", element.getDescription());
            list.add(map);
        }
        return list;
    }

    public String getDescription() {
        return description;
    }

}