Skip to content

Commit

Permalink
refactor: Optimize some code structures to improve readability
Browse files Browse the repository at this point in the history
  • Loading branch information
youngzil committed Dec 10, 2024
1 parent 28d2898 commit 47dd5d3
Show file tree
Hide file tree
Showing 21 changed files with 40 additions and 3 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 @@ -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,6 +77,7 @@ public void setCluster(String cluster) {
this.cluster = cluster;
}

@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 @@ -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 @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public DefaultRolePermissionService(final RoleRepository roleRepository,
* Create role with permissions, note that role name should be unique
*/
@Transactional
@Override
public Role createRoleWithPermissions(Role role, Set<Long> permissionIds) {
Role current = findRoleByRoleName(role.getRoleName());
Preconditions.checkState(current == null, "Role %s already exists!", role.getRoleName());
Expand Down Expand Up @@ -114,6 +115,7 @@ public Role createRoleWithPermissions(Role role, Set<Long> permissionIds) {
*/
@Transactional
@ApolloAuditLog(type = OpType.CREATE, name = "Auth.assignRoleToUsers")
@Override
public Set<String> assignRoleToUsers(String roleName, Set<String> userIds,
String operatorUserId) {
Role role = findRoleByRoleName(roleName);
Expand Down Expand Up @@ -144,6 +146,7 @@ public Set<String> assignRoleToUsers(String roleName, Set<String> userIds,
*/
@Transactional
@ApolloAuditLog(type = OpType.DELETE, name = "Auth.removeRoleFromUsers")
@Override
public void removeRoleFromUsers(
@ApolloAuditLogDataInfluence
@ApolloAuditLogDataInfluenceTable(tableName = "UserRole")
Expand All @@ -169,6 +172,7 @@ public void removeRoleFromUsers(
/**
* Query users with role
*/
@Override
public Set<UserInfo> queryUsersWithRole(String roleName) {
Role role = findRoleByRoleName(roleName);

Expand All @@ -191,13 +195,15 @@ public Set<UserInfo> queryUsersWithRole(String roleName) {
/**
* Find role by role name, note that roleName should be unique
*/
@Override
public Role findRoleByRoleName(String roleName) {
return roleRepository.findTopByRoleName(roleName);
}

/**
* Check whether user has the permission
*/
@Override
public boolean userHasPermission(String userId, String permissionType, String targetId) {
Permission permission =
permissionRepository.findTopByPermissionTypeAndTargetId(permissionType, targetId);
Expand Down Expand Up @@ -242,6 +248,7 @@ public List<Role> findUserRoles(String userId) {
return Lists.newLinkedList(roleRepository.findAllById(roleIds));
}

@Override
public boolean isSuperAdmin(String userId) {
return portalConfig.superAdmins().contains(userId);
}
Expand All @@ -250,6 +257,7 @@ public boolean isSuperAdmin(String userId) {
* Create permission, note that permissionType + targetId should be unique
*/
@Transactional
@Override
public Permission createPermission(Permission permission) {
String permissionType = permission.getPermissionType();
String targetId = permission.getTargetId();
Expand All @@ -265,6 +273,7 @@ public Permission createPermission(Permission permission) {
* Create permissions, note that permissionType + targetId should be unique
*/
@Transactional
@Override
public Set<Permission> createPermissions(Set<Permission> permissions) {
Multimap<String, String> targetIdPermissionTypes = HashMultimap.create();
for (Permission permission : permissions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
* @author Jason Song([email protected])
Expand All @@ -36,7 +37,7 @@ public List<UserInfo> searchUsers(String keyword, int offset, int limit, boolean

@Override
public UserInfo findByUserId(String userId) {
if (userId.equals("apollo")) {
if (Objects.equals(userId, "apollo")) {
return assembleDefaultUser();
}
return null;
Expand Down

0 comments on commit 47dd5d3

Please sign in to comment.