Skip to content

Commit b66b78b

Browse files
committed
Fixed some code smells in apollo-portal module
Signed-off-by: WillardHu <wei.hu@daocloud.io>
1 parent ec9534f commit b66b78b

6 files changed

Lines changed: 16 additions & 25 deletions

File tree

apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/filter/ConsumerAuthenticationFilter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
* @author Jason Song(song_s@ctrip.com)
3636
*/
3737
public class ConsumerAuthenticationFilter implements Filter {
38-
private ConsumerAuthUtil consumerAuthUtil;
39-
private ConsumerAuditUtil consumerAuditUtil;
38+
private final ConsumerAuthUtil consumerAuthUtil;
39+
private final ConsumerAuditUtil consumerAuditUtil;
4040

4141
public ConsumerAuthenticationFilter(ConsumerAuthUtil consumerAuthUtil, ConsumerAuditUtil consumerAuditUtil) {
4242
this.consumerAuthUtil = consumerAuthUtil;

apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/service/ConsumerService.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,11 @@ public Set<String> findAppIdsAuthorizedByConsumerId(long consumerId) {
269269
List<Long> roleIds = consumerRoles.stream().map(ConsumerRole::getRoleId)
270270
.collect(Collectors.toList());
271271

272-
Set<String> appIds = this.findAppIdsByRoleIds(roleIds);
273-
return appIds;
272+
return this.findAppIdsByRoleIds(roleIds);
274273
}
275274

276275
private List<ConsumerRole> findConsumerRolesByConsumerId(long consumerId) {
277-
List<ConsumerRole> consumerRoles = this.consumerRoleRepository.findByConsumerId(consumerId);
278-
return consumerRoles;
276+
return this.consumerRoleRepository.findByConsumerId(consumerId);
279277
}
280278

281279
private Set<String> findAppIdsByRoleIds(List<Long> roleIds) {

apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/util/ConsumerAuditUtil.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@
4141
@Service
4242
public class ConsumerAuditUtil implements InitializingBean {
4343
private static final int CONSUMER_AUDIT_MAX_SIZE = 10000;
44-
private BlockingQueue<ConsumerAudit> audits = Queues.newLinkedBlockingQueue(CONSUMER_AUDIT_MAX_SIZE);
44+
private final BlockingQueue<ConsumerAudit> audits = Queues.newLinkedBlockingQueue(CONSUMER_AUDIT_MAX_SIZE);
4545
private final ExecutorService auditExecutorService;
4646
private final AtomicBoolean auditStopped;
47-
private int BATCH_SIZE = 100;
48-
private long BATCH_TIMEOUT = 5;
49-
private TimeUnit BATCH_TIMEUNIT = TimeUnit.SECONDS;
47+
private static final int BATCH_SIZE = 100;
48+
private static final long BATCH_TIMEOUT = 5;
49+
private static final TimeUnit BATCH_TIMEUNIT = TimeUnit.SECONDS;
5050

5151
private final ConsumerService consumerService;
5252

apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/util/OpenApiBeanUtils.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
public class OpenApiBeanUtils {
5252

5353
private static final Gson GSON = new Gson();
54-
private static Type type = new TypeToken<Map<String, String>>() {}.getType();
54+
private static final Type TYPE = new TypeToken<Map<String, String>>() {}.getType();
5555

5656
public static OpenItemDTO transformFromItemDTO(ItemDTO item) {
5757
Preconditions.checkArgument(item != null);
@@ -78,7 +78,7 @@ public static OpenReleaseDTO transformFromReleaseDTO(ReleaseDTO release) {
7878

7979
OpenReleaseDTO openReleaseDTO = BeanUtils.transform(OpenReleaseDTO.class, release);
8080

81-
Map<String, String> configs = GSON.fromJson(release.getConfigurations(), type);
81+
Map<String, String> configs = GSON.fromJson(release.getConfigurations(), TYPE);
8282

8383
openReleaseDTO.setConfigurations(configs);
8484
return openReleaseDTO;
@@ -100,7 +100,7 @@ public static OpenNamespaceDTO transformFromNamespaceBO(NamespaceBO namespaceBO)
100100
List<ItemBO> itemBOs = namespaceBO.getItems();
101101
if (!CollectionUtils.isEmpty(itemBOs)) {
102102
items.addAll(itemBOs.stream().map(itemBO -> transformFromItemDTO(itemBO.getItem()))
103-
.collect(Collectors.toList()));
103+
.collect(Collectors.toList()));
104104
}
105105
openNamespaceDTO.setItems(items);
106106
return openNamespaceDTO;
@@ -113,11 +113,9 @@ public static List<OpenNamespaceDTO> batchTransformFromNamespaceBOs(
113113
return Collections.emptyList();
114114
}
115115

116-
List<OpenNamespaceDTO> openNamespaceDTOs =
117-
namespaceBOs.stream().map(OpenApiBeanUtils::transformFromNamespaceBO)
116+
return namespaceBOs.stream()
117+
.map(OpenApiBeanUtils::transformFromNamespaceBO)
118118
.collect(Collectors.toCollection(LinkedList::new));
119-
120-
return openNamespaceDTOs;
121119
}
122120

123121
public static OpenNamespaceLockDTO transformFromNamespaceLockDTO(String namespaceName,

apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/AppController.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public List<OpenEnvClusterDTO> loadEnvClusterInfo(@PathVariable String appId){
7070
for (Env env : envs) {
7171
OpenEnvClusterDTO envCluster = new OpenEnvClusterDTO();
7272

73-
envCluster.setEnv(env.name());
73+
envCluster.setEnv(env.getName());
7474
List<ClusterDTO> clusterDTOs = clusterService.findClusters(env, appId);
7575
envCluster.setClusters(BeanUtils.toPropertySet("name", clusterDTOs));
7676

@@ -84,7 +84,7 @@ public List<OpenEnvClusterDTO> loadEnvClusterInfo(@PathVariable String appId){
8484
@GetMapping("/apps")
8585
public List<OpenAppDTO> findApps(@RequestParam(value = "appIds", required = false) String appIds) {
8686
final List<App> apps = new ArrayList<>();
87-
if (StringUtils.isEmpty(appIds)) {
87+
if (!StringUtils.hasLength(appIds)) {
8888
apps.addAll(appService.findAll());
8989
} else {
9090
apps.addAll(appService.findByAppIds(Sets.newHashSet(appIds.split(","))));
@@ -102,8 +102,7 @@ public List<OpenAppDTO> findAppsAuthorized(HttpServletRequest request) {
102102
Set<String> appIds = this.consumerService.findAppIdsAuthorizedByConsumerId(consumerId);
103103

104104
List<App> apps = this.appService.findByAppIds(appIds);
105-
List<OpenAppDTO> openAppDTOS = OpenApiBeanUtils.transformFromApps(apps);
106-
return openAppDTOS;
105+
return OpenApiBeanUtils.transformFromApps(apps);
107106
}
108107

109108
}

apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/NamespaceBranchController.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616
*/
1717
package com.ctrip.framework.apollo.openapi.v1.controller;
1818

19-
/**
20-
* Created by qianjie on 8/10/17.
21-
*/
22-
2319
import com.ctrip.framework.apollo.common.dto.GrayReleaseRuleDTO;
2420
import com.ctrip.framework.apollo.common.dto.NamespaceDTO;
2521
import com.ctrip.framework.apollo.common.exception.BadRequestException;

0 commit comments

Comments
 (0)