Search in sources :

Example 6 with RoleVO

use of com.netsteadfast.greenstep.vo.RoleVO in project bamboobsc by billchen198318.

the class RoleLogicServiceImpl method findForAccountRoleEnableAndAll.

/**
	 * 找出全部的role與某帳戶下的role
	 * 
	 * map 中的  key 
	 * enable	- 帳戶下的role
	 * all	- 所有role
	 * 
	 * @param accountOid
	 * @return
	 * @throws ServiceException
	 * @throws Exception
	 */
@Override
public Map<String, List<RoleVO>> findForAccountRoleEnableAndAll(String accountOid) throws ServiceException, Exception {
    if (super.isBlank(accountOid)) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK));
    }
    AccountVO account = new AccountVO();
    account.setOid(accountOid);
    DefaultResult<AccountVO> aResult = this.accountService.findObjectByOid(account);
    if (aResult.getValue() == null) {
        throw new ServiceException(aResult.getSystemMessage().getValue());
    }
    account = aResult.getValue();
    Map<String, List<RoleVO>> roleMap = new HashMap<String, List<RoleVO>>();
    List<RoleVO> enableRole = this.roleService.findForAccount(account.getAccount());
    List<RoleVO> allRole = this.roleService.findForAll();
    roleMap.put("enable", enableRole);
    roleMap.put("all", allRole);
    return roleMap;
}
Also used : UserRoleVO(com.netsteadfast.greenstep.vo.UserRoleVO) SysMenuRoleVO(com.netsteadfast.greenstep.vo.SysMenuRoleVO) RoleVO(com.netsteadfast.greenstep.vo.RoleVO) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) HashMap(java.util.HashMap) List(java.util.List) AccountVO(com.netsteadfast.greenstep.vo.AccountVO)

Example 7 with RoleVO

use of com.netsteadfast.greenstep.vo.RoleVO in project bamboobsc by billchen198318.

the class RoleLogicServiceImpl method updateUserRole.

/**
	 * 更新帳戶的role
	 * 
	 * @param accountOid
	 * @param roles
	 * @return
	 * @throws ServiceException
	 * @throws Exception
	 */
@ServiceMethodAuthority(type = { ServiceMethodType.UPDATE })
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = { RuntimeException.class, IOException.class, Exception.class })
@Override
public DefaultResult<Boolean> updateUserRole(String accountOid, List<String> roles) throws ServiceException, Exception {
    if (super.isBlank(accountOid)) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK));
    }
    AccountVO account = new AccountVO();
    account.setOid(accountOid);
    DefaultResult<AccountVO> aResult = this.accountService.findObjectByOid(account);
    if (aResult.getValue() == null) {
        throw new ServiceException(aResult.getSystemMessage().getValue());
    }
    account = aResult.getValue();
    DefaultResult<Boolean> result = new DefaultResult<Boolean>();
    result.setValue(false);
    result.setSystemMessage(new SystemMessage(SysMessageUtil.get(GreenStepSysMsgConstants.UPDATE_FAIL)));
    this.deleteUserRoleByAccount(account);
    for (int i = 0; roles != null && i < roles.size(); i++) {
        String roleOid = roles.get(i).trim();
        if (super.isBlank(roleOid)) {
            continue;
        }
        RoleVO role = new RoleVO();
        role.setOid(roleOid);
        DefaultResult<RoleVO> rResult = this.roleService.findObjectByOid(role);
        if (rResult.getValue() == null) {
            throw new ServiceException(rResult.getSystemMessage().getValue());
        }
        role = rResult.getValue();
        UserRoleVO userRole = new UserRoleVO();
        userRole.setAccount(account.getAccount());
        userRole.setRole(role.getRole());
        userRole.setDescription("");
        DefaultResult<UserRoleVO> urResult = this.userRoleService.saveObject(userRole);
        if (urResult.getValue() == null) {
            throw new ServiceException(urResult.getSystemMessage().getValue());
        }
    }
    result.setValue(true);
    result.setSystemMessage(new SystemMessage(SysMessageUtil.get(GreenStepSysMsgConstants.UPDATE_SUCCESS)));
    return result;
}
Also used : SystemMessage(com.netsteadfast.greenstep.base.model.SystemMessage) UserRoleVO(com.netsteadfast.greenstep.vo.UserRoleVO) AccountVO(com.netsteadfast.greenstep.vo.AccountVO) UserRoleVO(com.netsteadfast.greenstep.vo.UserRoleVO) SysMenuRoleVO(com.netsteadfast.greenstep.vo.SysMenuRoleVO) RoleVO(com.netsteadfast.greenstep.vo.RoleVO) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) DefaultResult(com.netsteadfast.greenstep.base.model.DefaultResult) ServiceMethodAuthority(com.netsteadfast.greenstep.base.model.ServiceMethodAuthority) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with RoleVO

use of com.netsteadfast.greenstep.vo.RoleVO in project bamboobsc by billchen198318.

the class RoleLogicServiceImpl method createPermission.

/**
	 * 產生 TB_ROLE_PERMISSION 資料
	 * 
	 * @param permission
	 * @param roleOid
	 * @return
	 * @throws ServiceException
	 * @throws Exception
	 */
@ServiceMethodAuthority(type = { ServiceMethodType.INSERT, ServiceMethodType.UPDATE })
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = { RuntimeException.class, IOException.class, Exception.class })
@Override
public DefaultResult<RolePermissionVO> createPermission(RolePermissionVO permission, String roleOid) throws ServiceException, Exception {
    if (super.isBlank(roleOid) || permission == null || super.isBlank(permission.getPermission())) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK));
    }
    RoleVO role = new RoleVO();
    role.setOid(roleOid);
    DefaultResult<RoleVO> rResult = this.roleService.findObjectByOid(role);
    if (rResult.getValue() == null) {
        throw new ServiceException(rResult.getSystemMessage().getValue());
    }
    role = rResult.getValue();
    if (Constants.SUPER_ROLE_ADMIN.equals(role.getRole()) || Constants.SUPER_ROLE_ALL.equals(role.getRole())) {
        throw new ServiceException("Administrator or super role no need to set permission!");
    }
    permission.setRole(role.getRole());
    if (super.defaultString(permission.getDescription()).length() > MAX_DESCRIPTION_LENGTH) {
        permission.setDescription(permission.getDescription().substring(0, MAX_DESCRIPTION_LENGTH));
    }
    return this.rolePermissionService.saveObject(permission);
}
Also used : UserRoleVO(com.netsteadfast.greenstep.vo.UserRoleVO) SysMenuRoleVO(com.netsteadfast.greenstep.vo.SysMenuRoleVO) RoleVO(com.netsteadfast.greenstep.vo.RoleVO) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) ServiceMethodAuthority(com.netsteadfast.greenstep.base.model.ServiceMethodAuthority) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with RoleVO

use of com.netsteadfast.greenstep.vo.RoleVO in project bamboobsc by billchen198318.

the class RoleSaveOrUpdateAction method saveCopyAsNew.

private void saveCopyAsNew() throws ControllerException, AuthorityException, ServiceException, Exception {
    this.checkFields();
    RoleVO role = new RoleVO();
    this.transformFields2ValueObject(role, new String[] { "role", "description" });
    DefaultResult<RoleVO> result = this.roleLogicService.copyAsNew(this.getFields().get("fromRoleOid"), role);
    this.message = result.getSystemMessage().getValue();
    if (result.getValue() == null) {
        return;
    }
    this.success = IS_YES;
}
Also used : RoleVO(com.netsteadfast.greenstep.vo.RoleVO)

Example 10 with RoleVO

use of com.netsteadfast.greenstep.vo.RoleVO in project bamboobsc by billchen198318.

the class RoleSaveOrUpdateAction method save.

/**
	 * 建立 TB_ROLE 資料
	 * 
	 * @throws ControllerException
	 * @throws AuthorityException
	 * @throws ServiceException
	 * @throws Exception
	 */
private void save() throws ControllerException, AuthorityException, ServiceException, Exception {
    this.checkFields();
    RoleVO role = new RoleVO();
    this.transformFields2ValueObject(role, new String[] { "role", "description" });
    DefaultResult<RoleVO> result = this.roleLogicService.create(role);
    this.message = result.getSystemMessage().getValue();
    if (result.getValue() == null) {
        return;
    }
    this.success = IS_YES;
}
Also used : RoleVO(com.netsteadfast.greenstep.vo.RoleVO)

Aggregations

RoleVO (com.netsteadfast.greenstep.vo.RoleVO)12 ServiceException (com.netsteadfast.greenstep.base.exception.ServiceException)8 SysMenuRoleVO (com.netsteadfast.greenstep.vo.SysMenuRoleVO)6 UserRoleVO (com.netsteadfast.greenstep.vo.UserRoleVO)6 ServiceMethodAuthority (com.netsteadfast.greenstep.base.model.ServiceMethodAuthority)5 Transactional (org.springframework.transaction.annotation.Transactional)5 HashMap (java.util.HashMap)4 DefaultResult (com.netsteadfast.greenstep.base.model.DefaultResult)3 SystemMessage (com.netsteadfast.greenstep.base.model.SystemMessage)3 TbSysMenuRole (com.netsteadfast.greenstep.po.hbm.TbSysMenuRole)2 AccountVO (com.netsteadfast.greenstep.vo.AccountVO)2 SysProgVO (com.netsteadfast.greenstep.vo.SysProgVO)2 List (java.util.List)2 TbRolePermission (com.netsteadfast.greenstep.po.hbm.TbRolePermission)1 EmployeeVO (com.netsteadfast.greenstep.vo.EmployeeVO)1 OrganizationVO (com.netsteadfast.greenstep.vo.OrganizationVO)1 RolePermissionVO (com.netsteadfast.greenstep.vo.RolePermissionVO)1