You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
2.9 KiB
65 lines
2.9 KiB
3 years ago
|
/*
|
||
|
* Copyright (C), 2018-2021
|
||
|
* Project: starter
|
||
|
* FileName: CustomRoleServiceKit
|
||
|
* Author: xx
|
||
|
* Date: 2021/5/14 10:31
|
||
|
*/
|
||
|
package com.fr.plugin.dingtalksyn.kit;
|
||
|
|
||
|
import com.fr.decision.authority.AuthorityContext;
|
||
|
import com.fr.decision.authority.base.constant.SoftRoleType;
|
||
|
import com.fr.decision.authority.base.constant.type.operation.ManualOperationType;
|
||
|
import com.fr.decision.authority.data.CustomRole;
|
||
|
import com.fr.decision.record.OperateMessage;
|
||
|
import com.fr.decision.webservice.bean.user.RoleBean;
|
||
|
import com.fr.decision.webservice.exception.general.DuplicatedNameException;
|
||
|
import com.fr.decision.webservice.utils.ControllerFactory;
|
||
|
import com.fr.decision.webservice.v10.user.CustomRoleService;
|
||
|
import com.fr.intelli.record.MetricRegistry;
|
||
|
import com.fr.stable.query.QueryFactory;
|
||
|
import com.fr.stable.query.condition.QueryCondition;
|
||
|
import com.fr.stable.query.restriction.Restriction;
|
||
|
import com.fr.stable.query.restriction.RestrictionFactory;
|
||
|
|
||
|
/**
|
||
|
* <Function Description><br>
|
||
|
* <CustomRoleServiceKit>
|
||
|
*
|
||
|
* @author xx
|
||
|
* @since 1.0.0
|
||
|
*/
|
||
|
public class CustomRoleServiceKit extends CustomRoleService {
|
||
|
private static volatile CustomRoleServiceKit customRoleServiceKit = null;
|
||
|
|
||
|
public CustomRoleServiceKit() {
|
||
|
}
|
||
|
|
||
|
public static CustomRoleServiceKit getInstance() {
|
||
|
if (customRoleServiceKit == null) {
|
||
|
customRoleServiceKit = new CustomRoleServiceKit();
|
||
|
}
|
||
|
return customRoleServiceKit;
|
||
|
}
|
||
|
|
||
|
public void addCustomRole(String username, RoleBean roleBean) throws Exception {
|
||
|
this.checkDuplicatedCustomRole(roleBean.getText());
|
||
|
CustomRole customRole = (new CustomRole()).id(roleBean.getId()).name(roleBean.getText()).description(roleBean.getDescription()).creationType(ManualOperationType.KEY).lastOperationType(ManualOperationType.KEY).enable(true);
|
||
|
ControllerFactory.getInstance().getCustomRoleController(username).addCustomRole(username, customRole);
|
||
|
this.deleteSoftData(customRole.getName());
|
||
|
MetricRegistry.getMetric().submit(OperateMessage.build("Dec-Module-User_Manager", "Dec-Role", roleBean.getText(), "Dec-Log_Add"));
|
||
|
}
|
||
|
|
||
|
private void checkDuplicatedCustomRole(String roleName) throws Exception {
|
||
|
QueryCondition queryCondition = QueryFactory.create().addRestriction(RestrictionFactory.eq("name", roleName));
|
||
|
CustomRole customRole = (CustomRole) AuthorityContext.getInstance().getCustomRoleController().findOne(queryCondition);
|
||
|
if (customRole != null) {
|
||
|
throw new DuplicatedNameException();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void deleteSoftData(String roleName) throws Exception {
|
||
|
QueryCondition queryCondition = QueryFactory.create().addRestriction(RestrictionFactory.and(new Restriction[]{RestrictionFactory.eq("deletedName", roleName), RestrictionFactory.eq("type", SoftRoleType.CUSTOM)}));
|
||
|
AuthorityContext.getInstance().getSoftDataController().remove(queryCondition);
|
||
|
}
|
||
|
}
|