Search in sources :

Example 96 with RdosDefineException

use of com.dtstack.taier.common.exception.RdosDefineException in project Taier by DTStack.

the class ReadWriteLockService method checkLock.

/**
 * 锁检查,判断是否有其他人也在修改相同的文件
 * @param userId
 * @param tenantId
 * @param relationId
 * @param type
 * @param lockVersion
 * @param relationLocalVersion
 * @param relationVersion
 * @return
 */
private ReadWriteLockVO checkLock(Long userId, Long tenantId, Long relationId, ReadWriteLockType type, Integer lockVersion, Integer relationLocalVersion, Integer relationVersion) {
    BatchReadWriteLock readWriteLock = developReadWriteLockDao.getByTenantIdAndRelationIdAndType(tenantId, relationId, type.name());
    if (readWriteLock == null) {
        throw new RdosDefineException(ErrorCode.LOCK_IS_NOT_EXISTS);
    }
    Long modifyUserId = readWriteLock.getModifyUserId();
    int version = readWriteLock.getVersion();
    // 初始化返回对象
    ReadWriteLockVO readWriteLockVO = new ReadWriteLockVO();
    readWriteLockVO.setGmtModified(readWriteLock.getGmtModified());
    readWriteLockVO.setLastKeepLockUserName(userService.getUserName(modifyUserId));
    // 任务版本是否保持一致
    if (!relationLocalVersion.equals(relationVersion)) {
        // 表示已经被提交了
        // 提示任务版本已经更新不能在提交,是否保存到本地,或取消修改
        readWriteLockVO.setResult(TaskLockStatus.UPDATE_COMPLETED.getVal());
        return readWriteLockVO;
    } else if (modifyUserId.equals(userId) && version == lockVersion) {
        readWriteLockVO.setResult(TaskLockStatus.TO_UPDATE.getVal());
        readWriteLockVO.setVersion(lockVersion);
        return readWriteLockVO;
    } else {
        // 提示其他人也正在编辑,是否取消修改
        readWriteLockVO.setResult(TaskLockStatus.TO_CONFIRM.getVal());
        return readWriteLockVO;
    }
}
Also used : RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) ReadWriteLockVO(com.dtstack.taier.develop.dto.devlop.ReadWriteLockVO) BatchReadWriteLock(com.dtstack.taier.dao.domain.BatchReadWriteLock)

Example 97 with RdosDefineException

use of com.dtstack.taier.common.exception.RdosDefineException in project Taier by DTStack.

the class ReadWriteLockService method forceUpdateLock.

/**
 * @param userId
 * @param type
 * @param relationId
 * @param tenantId
 * @return
 */
private ReadWriteLockVO forceUpdateLock(Long userId, ReadWriteLockType type, Long relationId, Long tenantId) {
    BatchReadWriteLock readWriteLock = developReadWriteLockDao.getByTenantIdAndRelationIdAndType(tenantId, relationId, type.name());
    if (readWriteLock != null) {
        developReadWriteLockDao.updateVersionAndModifyUserIdDefinitized(readWriteLock.getId(), userId);
        readWriteLock = developReadWriteLockDao.getOne(readWriteLock.getId());
        ReadWriteLockVO readWriteLockVO = ReadWriteLockVO.toVO(readWriteLock);
        String userName = userService.getUserName(readWriteLock.getModifyUserId());
        readWriteLockVO.setLastKeepLockUserName(userName);
        return readWriteLockVO;
    } else {
        throw new RdosDefineException(ErrorCode.LOCK_IS_NOT_EXISTS);
    }
}
Also used : RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) ReadWriteLockVO(com.dtstack.taier.develop.dto.devlop.ReadWriteLockVO) BatchReadWriteLock(com.dtstack.taier.dao.domain.BatchReadWriteLock)

Example 98 with RdosDefineException

use of com.dtstack.taier.common.exception.RdosDefineException in project Taier by DTStack.

the class TokenService method decryption.

public DTToken decryption(String tokenText) {
    Assert.notNull(tokenText, "JWT Token Text can't blank.");
    try {
        /**
         * 验证
         */
        DecodedJWT jwt = JWT.require(Algorithm.HMAC256(JWT_TOKEN)).build().verify(tokenText);
        DTToken token = new DTToken();
        token.setUserName(jwt.getClaim(DTToken.USER_NAME).asString());
        token.setUserId(Long.parseLong(jwt.getClaim(DTToken.USER_ID).asString()));
        if (!jwt.getClaim(DTToken.TENANT_ID).isNull()) {
            token.setTenantId(Long.parseLong(jwt.getClaim(DTToken.TENANT_ID).asString()));
        }
        token.setExpireAt(jwt.getExpiresAt());
        return token;
    } catch (UnsupportedEncodingException e) {
        if (log.isErrorEnabled()) {
            log.error("JWT Token decode Error.", e);
        }
        throw new RdosDefineException("DT Token解码异常.");
    } catch (TokenExpiredException e) {
        if (log.isErrorEnabled()) {
            log.error("JWT Token expire.", e);
        }
        throw new RdosDefineException("DT Token已过期");
    }
}
Also used : TokenExpiredException(com.auth0.jwt.exceptions.TokenExpiredException) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DTToken(com.dtstack.taier.develop.dto.user.DTToken) DecodedJWT(com.auth0.jwt.interfaces.DecodedJWT)

Example 99 with RdosDefineException

use of com.dtstack.taier.common.exception.RdosDefineException in project Taier by DTStack.

the class TokenService method decryptionWithOutExpire.

public DTToken decryptionWithOutExpire(String tokenText) {
    Assert.notNull(tokenText, "JWT Token Text can't blank.");
    try {
        DecodedJWT jwt = JWT.require(Algorithm.HMAC256(JWT_TOKEN)).build().verify(tokenText);
        DTToken token = new DTToken();
        token.setUserName(jwt.getClaim(DTToken.USER_NAME).asString());
        token.setUserId(Long.parseLong(jwt.getClaim(DTToken.USER_ID).asString()));
        if (!jwt.getClaim(DTToken.TENANT_ID).isNull()) {
            token.setTenantId(Long.parseLong(jwt.getClaim(DTToken.TENANT_ID).asString()));
        }
        return token;
    } catch (UnsupportedEncodingException e) {
        throw new RdosDefineException("DT Token解码异常.");
    }
}
Also used : RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DTToken(com.dtstack.taier.develop.dto.user.DTToken) DecodedJWT(com.auth0.jwt.interfaces.DecodedJWT)

Example 100 with RdosDefineException

use of com.dtstack.taier.common.exception.RdosDefineException in project Taier by DTStack.

the class TokenService method encryptionWithOutExpire.

public String encryptionWithOutExpire(Long userId, String username, Long tenantId) {
    Objects.requireNonNull(userId);
    Objects.requireNonNull(username);
    try {
        Algorithm algorithm = Algorithm.HMAC256(JWT_TOKEN);
        JWTCreator.Builder builder = JWT.create();
        builder.withClaim(DTToken.USER_ID, String.valueOf(userId)).withClaim(DTToken.USER_NAME, username);
        // 若存在租户id,则增加租户id信息
        if (Objects.nonNull(tenantId)) {
            builder.withClaim(DTToken.TENANT_ID, String.valueOf(tenantId));
        }
        return builder.sign(algorithm);
    } catch (UnsupportedEncodingException e) {
        throw new RdosDefineException("dtToken生成异常.", e);
    }
}
Also used : JWTCreator(com.auth0.jwt.JWTCreator) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Algorithm(com.auth0.jwt.algorithms.Algorithm)

Aggregations

RdosDefineException (com.dtstack.taier.common.exception.RdosDefineException)176 JSONObject (com.alibaba.fastjson.JSONObject)80 IOException (java.io.IOException)24 ArrayList (java.util.ArrayList)20 EComponentType (com.dtstack.taier.common.enums.EComponentType)18 List (java.util.List)18 JSONArray (com.alibaba.fastjson.JSONArray)17 File (java.io.File)16 DtCenterDefException (com.dtstack.taier.common.exception.DtCenterDefException)15 Transactional (org.springframework.transaction.annotation.Transactional)15 BatchTask (com.dtstack.taier.dao.domain.BatchTask)14 ScheduleJob (com.dtstack.taier.dao.domain.ScheduleJob)13 Map (java.util.Map)13 ISourceDTO (com.dtstack.dtcenter.loader.dto.source.ISourceDTO)10 Component (com.dtstack.taier.dao.domain.Component)10 Resource (com.dtstack.taier.dao.dto.Resource)10 HashMap (java.util.HashMap)10 CollectionUtils (org.apache.commons.collections.CollectionUtils)10 ErrorCode (com.dtstack.taier.common.exception.ErrorCode)9 BatchCatalogue (com.dtstack.taier.dao.domain.BatchCatalogue)9