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;
}
}
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);
}
}
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已过期");
}
}
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解码异常.");
}
}
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);
}
}
Aggregations