Skip to content

Commit

Permalink
Code style-Optimize some code structures to improve readability (#5293)
Browse files Browse the repository at this point in the history
  • Loading branch information
youngzil authored Dec 14, 2024
1 parent 52df66e commit 939f890
Show file tree
Hide file tree
Showing 25 changed files with 65 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void appendDataInfluence(String entityName, String entityId, String field
@Override
public void appendDataInfluences(List<Object> entities, Class<?> beanDefinition) {
String tableName = ApolloAuditUtil.getApolloAuditLogTableName(beanDefinition);
if (Objects.isNull(tableName) || tableName.equals("")) {
if (Objects.isNull(tableName) || Objects.equals(tableName, "")) {
return;
}
List<Field> dataInfluenceFields = ApolloAuditUtil.getAnnotatedFields(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.ctrip.framework.apollo.audit.dto.ApolloAuditLogDataInfluenceDTO;
import com.ctrip.framework.apollo.audit.dto.ApolloAuditLogDetailsDTO;
import com.ctrip.framework.apollo.audit.dto.ApolloAuditLogDTO;
import java.util.Collections;
import java.util.Date;
import java.util.List;

Expand Down Expand Up @@ -50,28 +51,28 @@ public void appendDataInfluences(List<Object> entities, Class<?> beanDefinition)

@Override
public List<ApolloAuditLogDTO> queryLogs(int page, int size) {
return null;
return Collections.emptyList();
}

@Override
public List<ApolloAuditLogDTO> queryLogsByOpName(String opName, Date startDate,
Date endDate, int page, int size) {
return null;
return Collections.emptyList();
}

@Override
public List<ApolloAuditLogDetailsDTO> queryTraceDetails(String traceId) {
return null;
return Collections.emptyList();
}

@Override
public List<ApolloAuditLogDataInfluenceDTO> queryDataInfluencesByField(String entityName,
String entityId, String fieldName, int page, int size) {
return null;
return Collections.emptyList();
}

@Override
public List<ApolloAuditLogDTO> searchLogByNameOrTypeOrOperator(String query, int page, int size) {
return null;
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public void setOpName(String opName) {
this.opName = opName;
}

@Override
public String toString() {
return toStringHelper().add("entityName", entityName).add("entityId", entityId)
.add("opName", opName).add("comment", comment).toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public void setComment(String comment) {
this.comment = comment;
}

@Override
public String toString() {
return toStringHelper().add("name", name).add("appId", appId)
.add("parentClusterId", parentClusterId).add("comment", comment).toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public void setType(int type) {
this.type = type;
}

@Override
public String toString() {
return toStringHelper().add("namespaceId", namespaceId).add("key", key)
.add("type", type).add("value", value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public void setNamespaceName(String namespaceName) {
this.namespaceName = namespaceName;
}

@Override
public String toString() {
return toStringHelper().add("appId", appId).add("clusterName", clusterName)
.add("namespaceName", namespaceName).toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public void setPrivilType(String privilType) {
this.privilType = privilType;
}

@Override
public String toString() {
return toStringHelper().add("namespaceId", namespaceId).add("privilType", privilType)
.add("name", name).toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public void setAbandoned(boolean abandoned) {
isAbandoned = abandoned;
}

@Override
public String toString() {
return toStringHelper().add("name", name).add("appId", appId).add("clusterName", clusterName)
.add("namespaceName", namespaceName).add("configurations", configurations)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public void setOperationContext(String operationContext) {
this.operationContext = operationContext;
}

@Override
public String toString() {
return toStringHelper().add("appId", appId).add("clusterName", clusterName)
.add("namespaceName", namespaceName).add("branchName", branchName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public void setCluster(String cluster) {
this.cluster = cluster;
}

@Override
public String toString() {
return toStringHelper().add("key", key).add("value", value).add("comment", comment).toString();
return toStringHelper().add("key", key).add("value", value).add("cluster", cluster).add("comment", comment).toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ static ServiceRegistry convert(ServiceInstance instance) {
return serviceRegistry;
}

@Override
public void register(ServiceInstance instance) {
ServiceRegistry serviceRegistry = convert(instance);
this.serviceRegistryService.saveIfNotExistByServiceNameAndUri(serviceRegistry);
}

@Override
public void deregister(ServiceInstance instance) {
ServiceRegistry serviceRegistry = convert(instance);
this.serviceRegistryService.delete(serviceRegistry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

@Override
public String getServiceName() {
return serviceName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.ctrip.framework.apollo.core.ConfigConsts;
import com.google.common.base.Splitter;
import java.util.Collections;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -42,7 +43,7 @@ public static List<String> messageToList(String message) {
//message should be appId+cluster+namespace
if (keys.size() != 3) {
logger.error("message format invalid - {}", message);
return null;
return Collections.emptyList();
}
return keys;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

import java.util.List;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Set;
import java.util.concurrent.CountDownLatch;
Expand All @@ -33,7 +31,6 @@
import java.util.concurrent.TimeUnit;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

/**
* @author Jason Song([email protected])
Expand Down Expand Up @@ -80,7 +77,8 @@ public void testMessageToList() {

message = "appId+cluster";
keys = ReleaseMessageKeyGenerator.messageToList(message);
assertNull(keys);
assert keys != null;
assertEquals(0, keys.size());
}

private Runnable generateReleaseKeysTask(Namespace namespace, Set<String> releaseKeys,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.security.CodeSource;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import javax.sql.DataSource;
import org.springframework.boot.jdbc.DataSourceBuilder;
Expand Down Expand Up @@ -101,7 +102,7 @@ private static List<String> resolveLocations(Collection<String> locations,
private static Collection<String> convertRepositoryLocations(Collection<String> locations,
DataSource dataSource) {
if (CollectionUtils.isEmpty(locations)) {
return null;
return Collections.emptyList();
}
String repositoryDir = findRepositoryDirectory();
String suffix = findSuffix(dataSource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public void setOwnerName(String ownerName) {
this.ownerName = ownerName;
}

@Override
public String toString() {
return toStringHelper().add("name", name).add("appId", appId)
.add("orgId", orgId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public void setFormat(String format) {
this.format = format;
}

@Override
public String toString() {
return toStringHelper().add("name", name).add("appId", appId).add("comment", comment)
.add("format", format).add("isPublic", isPublic).toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ protected ToStringHelper toStringHelper() {
.add("dataChangeLastModifiedTime", dataChangeLastModifiedTime);
}

@Override
public String toString(){
return toStringHelper().toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public HealthCheckTask(ApplicationContext context) {
}
}

@Override
public void run() {

for (Env env : allEnvs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,22 @@ public RestTemplateFactory(final HttpMessageConverters httpMessageConverters,
this.apolloAuditHttpInterceptor = apolloAuditHttpInterceptor;
}

@Override
public RestTemplate getObject() {
return restTemplate;
}

@Override
public Class<RestTemplate> getObjectType() {
return RestTemplate.class;
}

@Override
public boolean isSingleton() {
return true;
}

@Override
public void afterPropertiesSet() throws UnsupportedEncodingException {

PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.ctrip.framework.apollo.portal.environment.Env;
import com.ctrip.framework.apollo.portal.environment.PortalMetaDomainService;
import java.util.List;
import java.util.Objects;
import javax.annotation.PostConstruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -145,6 +146,6 @@ private ServiceDTO[] getServerAddress(String metaServerAddress, String path) {
}

private boolean isValidVersion(String version) {
return !version.equals("java-null");
return !Objects.equals(version, "java-null");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public void setComment(String comment) {
this.comment = comment;
}

@Override
public String toString() {
return toStringHelper().add("key", key).add("value", value).add("comment", comment).toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public DefaultRoleInitializationService(final RolePermissionService rolePermissi
}

@Transactional
@Override
public void initAppRoles(App app) {
String appId = app.getAppId();

Expand Down Expand Up @@ -91,6 +92,7 @@ public void initAppRoles(App app) {
}

@Transactional
@Override
public void initNamespaceRoles(String appId, String namespaceName, String operator) {

String modifyNamespaceRoleName = RoleUtils.buildModifyNamespaceRoleName(appId, namespaceName);
Expand All @@ -107,6 +109,7 @@ public void initNamespaceRoles(String appId, String namespaceName, String operat
}

@Transactional
@Override
public void initNamespaceEnvRoles(String appId, String namespaceName, String operator) {
List<Env> portalEnvs = portalConfig.portalSupportedEnvs();

Expand All @@ -116,6 +119,7 @@ public void initNamespaceEnvRoles(String appId, String namespaceName, String ope
}

@Transactional
@Override
public void initNamespaceSpecificEnvRoles(String appId, String namespaceName, String env, String operator) {
String modifyNamespaceEnvRoleName = RoleUtils.buildModifyNamespaceRoleName(appId, namespaceName, env);
if (rolePermissionService.findRoleByRoleName(modifyNamespaceEnvRoleName) == null) {
Expand All @@ -131,6 +135,7 @@ public void initNamespaceSpecificEnvRoles(String appId, String namespaceName, St
}

@Transactional
@Override
public void initCreateAppRole() {
if (rolePermissionService.findRoleByRoleName(SystemRoleManagerService.CREATE_APPLICATION_ROLE_NAME) != null) {
return;
Expand Down Expand Up @@ -158,6 +163,7 @@ public void createManageAppMasterRole(String appId, String operator) {

// fix historical data
@Transactional
@Override
public void initManageAppMasterRole(String appId, String operator) {
String manageAppMasterRoleName = RoleUtils.buildAppRoleName(appId, PermissionType.MANAGE_APP_MASTER);
if (rolePermissionService.findRoleByRoleName(manageAppMasterRoleName) != null) {
Expand Down
Loading

0 comments on commit 939f890

Please sign in to comment.