Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue #765 fix some magic values #782

Merged
merged 1 commit into from
Jun 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public class ResourceTask {
private Date lastUpdateTime;

private static final String DEFAULT_SYSTEM = "dss";
private static final String SYSTEM = "system";
private static final String CLIENT_IP = "clientIp";

public static ResourceTask createUploadTask(String resourceId, String user,
Map<String, Object> properties) {
Expand All @@ -81,12 +83,12 @@ public static ResourceTask createUploadTask(String resourceId, String user,
resourceTask.setOperation(OperationEnum.UPLOAD.getValue());
resourceTask.setState(TaskState.SCHEDULED.getValue());
resourceTask.setSubmitUser(user);
if (null != properties.get("system")){
resourceTask.setSystem((String)properties.get("system"));
if (null != properties.get(SYSTEM)){
resourceTask.setSystem((String)properties.get(SYSTEM));
}else{
resourceTask.setSystem(DEFAULT_SYSTEM);
}
resourceTask.setClientIp((String)properties.get("clientIp"));
resourceTask.setClientIp((String)properties.get(CLIENT_IP));
resourceTask.setInstance(Sender.getThisInstance());
resourceTask.setStartTime(new Date());
resourceTask.setLastUpdateTime(new Date());
Expand All @@ -101,7 +103,7 @@ public static ResourceTask createUpdateTask(String resourceId, String version, S
resourceTask.setOperation(OperationEnum.UPDATE.getValue());
resourceTask.setState(TaskState.SCHEDULED.getValue());
resourceTask.setSubmitUser(user);
resourceTask.setClientIp((String)properties.get("clientIp"));
resourceTask.setClientIp((String)properties.get(CLIENT_IP));
resourceTask.setSystem(system);
resourceTask.setInstance(Sender.getThisInstance());
resourceTask.setStartTime(new Date());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class RestfulUtils {
private static final Long DAY = 24 * HOUR;
private static final Long MONTH = 30 * DAY;
private static final Long YEAR = 365 * DAY;
private static final String DATE = "date";

public static String getUserName(HttpServletRequest request)throws BmlAuthorityException{
String user;
try{
Expand Down Expand Up @@ -62,7 +64,7 @@ public static String getExpireTime(Date createTime, String expireType, String ex
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(Constant.TIME_FORMAT);
String retTime = null;

if ("date".equals(expireType)){
if (DATE.equals(expireType)){
return expireTime;
}else{
int num = Integer.parseInt(expireTime.substring(0, expireTime.length() - 1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
public abstract class AbstractSerializer<T> implements ContextSerializer<T> {




private static final String TYPE = "type";

public String getJsonValue(T t) throws CSErrorException {
if (null != t) {
Expand All @@ -44,7 +43,7 @@ public String getJsonValue(T t) throws CSErrorException {
public boolean accepts(String json) {
if (StringUtils.isNotBlank(json)) {
Map<String, String> value = CSCommonUtils.gson.fromJson(json, new HashMap<String, String>().getClass());
if (getType().equals(value.get("type"))) {
if (getType().equals(value.get(TYPE))) {
return true;
}
}
Expand All @@ -58,7 +57,7 @@ public String serialize(T t) throws CSErrorException {

if (accepts(t)) {
Map<String, String> map = new HashMap<>();
map.put("type", getType());
map.put(TYPE, getType());
map.put("value", getJsonValue(t));
return CSCommonUtils.gson.toJson(map);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class CSHighAvailableUtils {
private final static int HAID_PARTS_NUM = 2;
private final static Gson gson = new Gson();

private static final int TWO = 2;

public static boolean checkHAIDBasicFormat(String haid) {
if (StringUtils.isBlank(haid)) {
return false;
Expand All @@ -45,7 +47,7 @@ public static boolean checkHAIDBasicFormat(String haid) {
if (null != arr && arr.length == HAID_PARTS_NUM) {
int insLen = 0;
String [] lenArr = arr[0].split(HAID_INS_LEN_DELEMETER);
if (null == lenArr || lenArr.length < 2) {
if (null == lenArr || lenArr.length < TWO) {
return false;
}
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public class MethodInterceptorImpl implements MethodInterceptor {
private Object object;
private final Map<Integer, String> contextIDCacheMap = new HashMap<Integer, String>();

private static final String CONTEXTID = "contextid";
private static final String GETCONTEXTID = "getcontextid";

public MethodInterceptorImpl(AbstractContextHAManager contextHAManager, Object object) {
this.contextHAManager = contextHAManager;
this.object = object;
Expand All @@ -69,7 +72,7 @@ public Object intercept(Object o, Method method, Object[] args, MethodProxy meth
}

// ③方法名含有ContextID,并且有String类型参数,取第一个转换
if (method.getName().toLowerCase().contains("contextid")) {
if (method.getName().toLowerCase().contains(CONTEXTID)) {
for (int j = 0; j < args.length; j++) {
if (String.class.isInstance(args[j])) {
String pStr = (String)args[j];
Expand Down Expand Up @@ -172,7 +175,7 @@ private void convertContextIDBeforeInvoke(ContextID contextID, int index) throws

private void convertGetContextIDBeforeInvoke(Object object) throws CSErrorException {
for (Method innerMethod : object.getClass().getMethods()) {
if (innerMethod.getName().toLowerCase().contains("getcontextid")) {
if (innerMethod.getName().toLowerCase().contains(GETCONTEXTID)) {
try {
Object result = innerMethod.invoke(object);
if (null != object && ContextID.class.isInstance(result)) {
Expand All @@ -194,7 +197,7 @@ private void convertGetContextIDAfterInvoke(Object object) throws CSErrorExcepti
}

private void convertGetContextIDAfterInvokeMethod(Method method) throws CSErrorException {
if (method.getName().toLowerCase().contains("getcontextid")) {
if (method.getName().toLowerCase().contains(GETCONTEXTID)) {
Object result = null;
try {
result = method.invoke(object);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public class MdqTableRestfulApi {

private static final Logger logger = LoggerFactory.getLogger(MdqTableRestfulApi.class);

private static final String ASC = "asc";

@Autowired
private MdqService mdqService;
ObjectMapper mapper = new ObjectMapper();
Expand Down Expand Up @@ -100,7 +102,7 @@ public Response getTableStatisticInfo(@QueryParam("database") String database, @
List<MdqTablePartitionStatisticInfoVO> partitions = tableStatisticInfo.getPartitions();
if (partitions != null && !partitions.isEmpty()) {
//排序
if ("asc".equals(partitionSort)) {
if (ASC.equals(partitionSort)) {
partitions = partitions.stream().sorted(Comparator.comparing(MdqTablePartitionStatisticInfoVO::getName))
.collect(Collectors.toList());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public class ConfigurationRestfulApi {

ObjectMapper mapper = new ObjectMapper();

private static final String NULL = "null";

@GET
@Path("/addKeyForEngine")
public Response addKeyForEngine(@Context HttpServletRequest req,
Expand Down Expand Up @@ -168,7 +170,7 @@ public Response createFirstCategory(@Context HttpServletRequest request, JsonNod
String username = SecurityFilter.getLoginUsername(request);
String categoryName = jsonNode.get("categoryName").asText();
String description = jsonNode.get("description").asText();
if(StringUtils.isEmpty(categoryName) || categoryName.equals("null")){
if(StringUtils.isEmpty(categoryName) || categoryName.equals(NULL)){
throw new ConfigurationException("categoryName is null, cannot be added");
}
categoryService.createFirstCategory(categoryName, description);
Expand Down Expand Up @@ -196,10 +198,10 @@ public Response createSecondCategory(@Context HttpServletRequest request, JsonNo
if(StringUtils.isEmpty(categoryId) || categoryId <= 0){
throw new ConfigurationException("creator is null, cannot be added");
}
if(StringUtils.isEmpty(engineType) || engineType.toLowerCase().equals("null")){
if(StringUtils.isEmpty(engineType) || engineType.toLowerCase().equals(NULL)){
throw new ConfigurationException("engine type is null, cannot be added");
}
if(StringUtils.isEmpty(version) || version.toLowerCase().equals("null")){
if(StringUtils.isEmpty(version) || version.toLowerCase().equals(NULL)){
version = LabelUtils.COMMON_VALUE;
}
categoryService.createSecondCategory(categoryId, engineType, version, description);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class UserTaskResultCache {
Cache<String, TaskResult> resultCache;
Long lastCleaned;

private static final int ONE_THOUSAND = 1000;

public UserTaskResultCache() {
resultCache = CacheBuilder.newBuilder()
.expireAfterWrite((Long) QueryConfig.CACHE_MAX_EXPIRE_HOUR().getValue(), TimeUnit.DAYS)
Expand Down Expand Up @@ -78,7 +80,7 @@ public TaskResult get(String executionCode, Long readCacheBefore) {
resultCache.invalidate(md5);
return null;
}
if (taskResult.getCreatedAt() < System.currentTimeMillis() - readCacheBefore * 1000) {
if (taskResult.getCreatedAt() < System.currentTimeMillis() - readCacheBefore * ONE_THOUSAND) {
return null;
}
return taskResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

public class MD5Util {

private static final int SIXTY_FOUR = 64;
private static final int SIXTEEN = 16;

/**
* MD5加密
*
Expand All @@ -36,7 +39,7 @@ public static String getMD5(String src, boolean isUpper, Integer bit) {
try {
// 创建加密对象
MessageDigest md = MessageDigest.getInstance("md5");
if (bit == 64) {
if (bit == SIXTY_FOUR) {
BASE64Encoder bw = new BASE64Encoder();
String bsB64 = bw.encode(md.digest(src.getBytes(StandardCharsets.UTF_8)));
md5 = bsB64;
Expand All @@ -55,7 +58,7 @@ public static String getMD5(String src, boolean isUpper, Integer bit) {
sb.append(Integer.toHexString(i));
}
md5 = sb.toString();
if (bit == 16) {
if (bit == SIXTEEN) {
//截取32位md5为16位
String md16 = md5.substring(8, 24);
md5 = md16;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class UDFTreeServiceImpl implements UDFTreeService {

private static final Logger logger = Logger.getLogger(UDFTreeServiceImpl.class);

private static final int THREE = 3;

@Autowired
private UDFTreeDao udfTreeDao;

Expand Down Expand Up @@ -68,7 +70,7 @@ public class UDFTreeServiceImpl implements UDFTreeService {
@Override
public UDFTree initTree(String userName, String category) throws UDFException {
List<UDFTree> childrens = new ArrayList<>();
if(firstFloor.get(category) == null || firstFloor.get(category).size() != 3){
if(firstFloor.get(category) == null || firstFloor.get(category).size() != THREE){

List<UDFTree> root = new ArrayList<>();
//sys
Expand All @@ -81,7 +83,7 @@ public UDFTree initTree(String userName, String category) throws UDFException {
firstFloor.put(category, root);

}
for(int i = 0 ; i < 3; i++){
for(int i = 0; i < THREE; i++){
childrens.add(firstFloor.get(category).get(i));
}
childrens.add(getFirstFloor(userName, category));
Expand Down