Search in sources :

Example 1 with ServiceMethodAuthority

use of com.netsteadfast.greenstep.base.model.ServiceMethodAuthority in project bamboobsc by billchen198318.

the class ServiceAuthorityCheckAspect method isServiceMethodAuthority.

private boolean isServiceMethodAuthority(String serviceId, Annotation[] annotations, Subject subject) {
    if (annotations == null || annotations.length < 1) {
        // 沒有 @ServiceMethodAuthority 不要檢查權限
        return true;
    }
    boolean status = false;
    boolean foundServiceMethodAuthority = false;
    for (Annotation anno : annotations) {
        if (anno instanceof ServiceMethodAuthority) {
            foundServiceMethodAuthority = true;
            ServiceMethodType[] types = ((ServiceMethodAuthority) anno).type();
            for (int i = 0; types != null && !status && i < types.length; i++) {
                ServiceMethodType type = types[i];
                // 如 core.service.logic.ApplicationSystemLogicService#INSERT
                String methodPerm = serviceId + Constants.SERVICE_ID_TYPE_DISTINGUISH_SYMBOL + type.toString();
                if (subject.isPermitted(methodPerm)) {
                    status = true;
                }
            }
        }
    }
    if (!foundServiceMethodAuthority) {
        // 沒有 @ServiceMethodAuthority 不要檢查權限 
        return true;
    }
    return status;
}
Also used : ServiceMethodType(com.netsteadfast.greenstep.base.model.ServiceMethodType) ServiceMethodAuthority(com.netsteadfast.greenstep.base.model.ServiceMethodAuthority) Annotation(java.lang.annotation.Annotation) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint)

Example 2 with ServiceMethodAuthority

use of com.netsteadfast.greenstep.base.model.ServiceMethodAuthority in project bamboobsc by billchen198318.

the class BaseService method updateObject.

@SuppressWarnings({ "unchecked", "rawtypes" })
@ServiceMethodAuthority(type = { ServiceMethodType.UPDATE })
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = { RuntimeException.class, IOException.class, Exception.class })
public DefaultResult<T> updateObject(T object) throws ServiceException, Exception {
    if (object == null || !(object instanceof BaseValueObj)) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.OBJ_NULL));
    }
    DefaultResult<T> result = new DefaultResult<T>();
    Class<T> valueObjectClass = GenericsUtils.getSuperClassGenricType(getClass(), 0);
    Class<E> entityObjectClass = GenericsUtils.getSuperClassGenricType(getClass(), 1);
    E entityObject = entityObjectClass.newInstance();
    ((BaseEntity) entityObject).setOid(((BaseValueObj) object).getOid());
    E findEntity = this.findByOid(entityObject);
    if (findEntity == null) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.SEARCH_NO_DATA));
    }
    this.doMapper(object, findEntity, this.getMapperIdVo2Po());
    E updateEntity = null;
    try {
        ((BaseEntity) findEntity).setUuserid(this.getAccountId());
        ((BaseEntity) findEntity).setUdate(this.generateDate());
        updateEntity = this.getBaseDataAccessObject().update(findEntity);
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (updateEntity != null && ((BaseEntity) updateEntity).getOid() != null) {
        T updateValueObj = valueObjectClass.newInstance();
        this.doMapper(updateEntity, updateValueObj, this.getMapperIdPo2Vo());
        result.setValue(updateValueObj);
        result.setSystemMessage(new SystemMessage(SysMessageUtil.get(GreenStepSysMsgConstants.UPDATE_SUCCESS)));
    } else {
        result.setSystemMessage(new SystemMessage(SysMessageUtil.get(GreenStepSysMsgConstants.UPDATE_FAIL)));
    }
    return result;
}
Also used : SystemMessage(com.netsteadfast.greenstep.base.model.SystemMessage) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) BaseEntity(com.netsteadfast.greenstep.base.model.BaseEntity) BaseValueObj(com.netsteadfast.greenstep.base.model.BaseValueObj) DefaultResult(com.netsteadfast.greenstep.base.model.DefaultResult) IOException(java.io.IOException) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) ServiceMethodAuthority(com.netsteadfast.greenstep.base.model.ServiceMethodAuthority) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with ServiceMethodAuthority

use of com.netsteadfast.greenstep.base.model.ServiceMethodAuthority in project bamboobsc by billchen198318.

the class SimpleService method deleteEntity.

@ServiceMethodAuthority(type = { ServiceMethodType.DELETE })
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = { RuntimeException.class, IOException.class, Exception.class })
public DefaultResult<Boolean> deleteEntity(E object) throws ServiceException, Exception {
    if (object == null || !(object instanceof BaseEntity)) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.OBJ_NULL));
    }
    DefaultResult<Boolean> result = new DefaultResult<Boolean>();
    boolean status = false;
    if (this.countByOid(object) > 0) {
        this.delete(object);
        status = true;
    }
    result.setValue(status);
    if (status) {
        result.setSystemMessage(new SystemMessage(SysMessageUtil.get(GreenStepSysMsgConstants.DELETE_SUCCESS)));
    } else {
        result.setSystemMessage(new SystemMessage(SysMessageUtil.get(GreenStepSysMsgConstants.DELETE_FAIL)));
    }
    return result;
}
Also used : SystemMessage(com.netsteadfast.greenstep.base.model.SystemMessage) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) BaseEntity(com.netsteadfast.greenstep.base.model.BaseEntity) DefaultResult(com.netsteadfast.greenstep.base.model.DefaultResult) ServiceMethodAuthority(com.netsteadfast.greenstep.base.model.ServiceMethodAuthority) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with ServiceMethodAuthority

use of com.netsteadfast.greenstep.base.model.ServiceMethodAuthority in project bamboobsc by billchen198318.

the class SimpleService method updateEntity.

@SuppressWarnings({ "rawtypes" })
@ServiceMethodAuthority(type = { ServiceMethodType.UPDATE })
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = { RuntimeException.class, IOException.class, Exception.class })
public DefaultResult<E> updateEntity(E object) throws ServiceException, Exception {
    if (object == null || !(object instanceof BaseEntity)) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.OBJ_NULL));
    }
    DefaultResult<E> result = new DefaultResult<E>();
    try {
        ((BaseEntity) object).setUuserid(this.getAccountId());
        ((BaseEntity) object).setUdate(this.generateDate());
        object = this.getBaseDataAccessObject().update(object);
        if (object != null && ((BaseEntity) object).getOid() != null) {
            result.setValue(object);
            result.setSystemMessage(new SystemMessage(SysMessageUtil.get(GreenStepSysMsgConstants.UPDATE_SUCCESS)));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (result.getValue() == null) {
        result.setSystemMessage(new SystemMessage(SysMessageUtil.get(GreenStepSysMsgConstants.UPDATE_FAIL)));
    }
    return result;
}
Also used : SystemMessage(com.netsteadfast.greenstep.base.model.SystemMessage) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) BaseEntity(com.netsteadfast.greenstep.base.model.BaseEntity) DefaultResult(com.netsteadfast.greenstep.base.model.DefaultResult) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) ServiceMethodAuthority(com.netsteadfast.greenstep.base.model.ServiceMethodAuthority) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with ServiceMethodAuthority

use of com.netsteadfast.greenstep.base.model.ServiceMethodAuthority in project bamboobsc by billchen198318.

the class SimpleService method saveOrMergeEntity.

@ServiceMethodAuthority(type = { ServiceMethodType.INSERT, ServiceMethodType.UPDATE })
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = { RuntimeException.class, IOException.class, Exception.class })
@SuppressWarnings({ "rawtypes", "unchecked" })
private DefaultResult<E> saveOrMergeEntity(String type, boolean checkUK, E object) throws ServiceException, Exception {
    if (object == null || !(object instanceof BaseEntity)) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.OBJ_NULL));
    }
    DefaultResult<E> result = new DefaultResult<E>();
    if (checkUK) {
        int countByUK = 1;
        try {
            countByUK = this.getBaseDataAccessObject().countByUK(object);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (countByUK > 0) {
            throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.DATA_IS_EXIST));
        }
    }
    ((BaseEntity) object).setOid(this.generateOid());
    ((BaseEntity) object).setCuserid(this.getAccountId());
    ((BaseEntity) object).setCdate(this.generateDate());
    E insertEntity = null;
    try {
        if ("save".equals(type)) {
            insertEntity = this.getBaseDataAccessObject().save(object);
        } else {
            insertEntity = this.getBaseDataAccessObject().merge(object);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (insertEntity != null && ((BaseEntity) insertEntity).getOid() != null) {
        result.setValue(insertEntity);
        result.setSystemMessage(new SystemMessage(SysMessageUtil.get(GreenStepSysMsgConstants.INSERT_SUCCESS)));
    } else {
        result.setSystemMessage(new SystemMessage(SysMessageUtil.get(GreenStepSysMsgConstants.INSERT_FAIL)));
    }
    return result;
}
Also used : SystemMessage(com.netsteadfast.greenstep.base.model.SystemMessage) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) BaseEntity(com.netsteadfast.greenstep.base.model.BaseEntity) DefaultResult(com.netsteadfast.greenstep.base.model.DefaultResult) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) ServiceMethodAuthority(com.netsteadfast.greenstep.base.model.ServiceMethodAuthority) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ServiceMethodAuthority (com.netsteadfast.greenstep.base.model.ServiceMethodAuthority)95 ServiceException (com.netsteadfast.greenstep.base.exception.ServiceException)91 Transactional (org.springframework.transaction.annotation.Transactional)84 HashMap (java.util.HashMap)32 SystemMessage (com.netsteadfast.greenstep.base.model.SystemMessage)31 DefaultResult (com.netsteadfast.greenstep.base.model.DefaultResult)29 SysVO (com.netsteadfast.greenstep.vo.SysVO)13 LinkedHashMap (java.util.LinkedHashMap)13 Map (java.util.Map)12 AccountVO (com.netsteadfast.greenstep.vo.AccountVO)7 VisionVO (com.netsteadfast.greenstep.vo.VisionVO)7 BaseEntity (com.netsteadfast.greenstep.base.model.BaseEntity)6 EmployeeVO (com.netsteadfast.greenstep.vo.EmployeeVO)6 PerspectiveVO (com.netsteadfast.greenstep.vo.PerspectiveVO)6 IOException (java.io.IOException)6 BaseValueObj (com.netsteadfast.greenstep.base.model.BaseValueObj)5 RoleVO (com.netsteadfast.greenstep.vo.RoleVO)5 SysProgVO (com.netsteadfast.greenstep.vo.SysProgVO)5 UserRoleVO (com.netsteadfast.greenstep.vo.UserRoleVO)5 BbReportRoleView (com.netsteadfast.greenstep.po.hbm.BbReportRoleView)4