Commit 99a6f5dd authored by waters's avatar waters Committed by Jason Song

Refactor/remove redundant else (#2864)

parent 24cc3da1
...@@ -50,10 +50,9 @@ public class ItemController { ...@@ -50,10 +50,9 @@ public class ItemController {
Item managedEntity = itemService.findOne(appId, clusterName, namespaceName, entity.getKey()); Item managedEntity = itemService.findOne(appId, clusterName, namespaceName, entity.getKey());
if (managedEntity != null) { if (managedEntity != null) {
throw new BadRequestException("item already exists"); throw new BadRequestException("item already exists");
} else {
entity = itemService.save(entity);
builder.createItem(entity);
} }
entity = itemService.save(entity);
builder.createItem(entity);
dto = BeanUtils.transform(ItemDTO.class, entity); dto = BeanUtils.transform(ItemDTO.class, entity);
Commit commit = new Commit(); Commit commit = new Commit();
......
...@@ -100,9 +100,8 @@ public class ItemService { ...@@ -100,9 +100,8 @@ public class ItemService {
Namespace namespace = namespaceService.findOne(appId, clusterName, namespaceName); Namespace namespace = namespaceService.findOne(appId, clusterName, namespaceName);
if (namespace != null) { if (namespace != null) {
return findItemsWithoutOrdered(namespace.getId()); return findItemsWithoutOrdered(namespace.getId());
} else {
return Collections.emptyList();
} }
return Collections.emptyList();
} }
public List<Item> findItemsWithOrdered(Long namespaceId) { public List<Item> findItemsWithOrdered(Long namespaceId) {
...@@ -117,9 +116,8 @@ public class ItemService { ...@@ -117,9 +116,8 @@ public class ItemService {
Namespace namespace = namespaceService.findOne(appId, clusterName, namespaceName); Namespace namespace = namespaceService.findOne(appId, clusterName, namespaceName);
if (namespace != null) { if (namespace != null) {
return findItemsWithOrdered(namespace.getId()); return findItemsWithOrdered(namespace.getId());
} else {
return Collections.emptyList();
} }
return Collections.emptyList();
} }
public List<Item> findItemsModifiedAfterDate(long namespaceId, Date date) { public List<Item> findItemsModifiedAfterDate(long namespaceId, Date date) {
......
...@@ -242,9 +242,8 @@ public class ReleaseService { ...@@ -242,9 +242,8 @@ public class ReleaseService {
if (parentNamespace != null) { if (parentNamespace != null) {
return publishBranchNamespace(parentNamespace, namespace, operateNamespaceItems, return publishBranchNamespace(parentNamespace, namespace, operateNamespaceItems,
releaseName, releaseComment, operator, isEmergencyPublish, grayDelKeys); releaseName, releaseComment, operator, isEmergencyPublish, grayDelKeys);
}else {
throw new NotFoundException("Parent namespace not found");
} }
throw new NotFoundException("Parent namespace not found");
} }
private void checkLock(Namespace namespace, boolean isEmergencyPublish, String operator) { private void checkLock(Namespace namespace, boolean isEmergencyPublish, String operator) {
......
...@@ -119,10 +119,9 @@ public class HttpUtil { ...@@ -119,10 +119,9 @@ public class HttpUtil {
// 200 and 304 should not trigger IOException, thus we must throw the original exception out // 200 and 304 should not trigger IOException, thus we must throw the original exception out
if (statusCode == 200 || statusCode == 304) { if (statusCode == 200 || statusCode == 304) {
throw ex; throw ex;
} else {
// for status codes like 404, IOException is expected when calling conn.getInputStream()
throw new ApolloConfigStatusCodeException(statusCode, ex);
} }
// for status codes like 404, IOException is expected when calling conn.getInputStream()
throw new ApolloConfigStatusCodeException(statusCode, ex);
} }
if (statusCode == 200) { if (statusCode == 200) {
......
...@@ -12,9 +12,11 @@ public class TitanCondition implements Condition { ...@@ -12,9 +12,11 @@ public class TitanCondition implements Condition {
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
if (!StringUtils.isEmpty(context.getEnvironment().getProperty("fat.titan.url"))) { if (!StringUtils.isEmpty(context.getEnvironment().getProperty("fat.titan.url"))) {
return true; return true;
} else if (!StringUtils.isEmpty(context.getEnvironment().getProperty("uat.titan.url"))) { }
if (!StringUtils.isEmpty(context.getEnvironment().getProperty("uat.titan.url"))) {
return true; return true;
} else if (!StringUtils.isEmpty(context.getEnvironment().getProperty("pro.titan.url"))) { }
if (!StringUtils.isEmpty(context.getEnvironment().getProperty("pro.titan.url"))) {
return true; return true;
} }
return false; return false;
......
...@@ -44,11 +44,10 @@ public class DefaultProviderManager implements ProviderManager { ...@@ -44,11 +44,10 @@ public class DefaultProviderManager implements ProviderManager {
if (provider != null) { if (provider != null) {
return (T) provider; return (T) provider;
} else {
logger.error("No provider [{}] found in DefaultProviderManager, please make sure it is registered in DefaultProviderManager ",
clazz.getName());
return (T) NullProviderManager.provider;
} }
logger.error("No provider [{}] found in DefaultProviderManager, please make sure it is registered in DefaultProviderManager ",
clazz.getName());
return (T) NullProviderManager.provider;
} }
@Override @Override
......
...@@ -66,10 +66,9 @@ public class DefaultApplicationProvider implements ApplicationProvider { ...@@ -66,10 +66,9 @@ public class DefaultApplicationProvider implements ApplicationProvider {
if ("app.id".equals(name)) { if ("app.id".equals(name)) {
String val = getAppId(); String val = getAppId();
return val == null ? defaultValue : val; return val == null ? defaultValue : val;
} else {
String val = m_appProperties.getProperty(name, defaultValue);
return val == null ? defaultValue : val;
} }
String val = m_appProperties.getProperty(name, defaultValue);
return val == null ? defaultValue : val;
} }
@Override @Override
......
...@@ -10,12 +10,12 @@ public class DefaultNetworkProvider implements NetworkProvider { ...@@ -10,12 +10,12 @@ public class DefaultNetworkProvider implements NetworkProvider {
if ("host.address".equalsIgnoreCase(name)) { if ("host.address".equalsIgnoreCase(name)) {
String val = getHostAddress(); String val = getHostAddress();
return val == null ? defaultValue : val; return val == null ? defaultValue : val;
} else if ("host.name".equalsIgnoreCase(name)) { }
if ("host.name".equalsIgnoreCase(name)) {
String val = getHostName(); String val = getHostName();
return val == null ? defaultValue : val; return val == null ? defaultValue : val;
} else {
return defaultValue;
} }
return defaultValue;
} }
@Override @Override
......
...@@ -86,13 +86,13 @@ public class DefaultServerProvider implements ServerProvider { ...@@ -86,13 +86,13 @@ public class DefaultServerProvider implements ServerProvider {
if ("env".equalsIgnoreCase(name)) { if ("env".equalsIgnoreCase(name)) {
String val = getEnvType(); String val = getEnvType();
return val == null ? defaultValue : val; return val == null ? defaultValue : val;
} else if ("dc".equalsIgnoreCase(name)) { }
if ("dc".equalsIgnoreCase(name)) {
String val = getDataCenter(); String val = getDataCenter();
return val == null ? defaultValue : val; return val == null ? defaultValue : val;
} else {
String val = m_serverProperties.getProperty(name, defaultValue);
return val == null ? defaultValue : val.trim();
} }
String val = m_serverProperties.getProperty(name, defaultValue);
return val == null ? defaultValue : val.trim();
} }
@Override @Override
......
...@@ -64,7 +64,8 @@ public class EmbeddedApollo extends ExternalResource { ...@@ -64,7 +64,8 @@ public class EmbeddedApollo extends ExternalResource {
if (request.getPath().startsWith("/notifications/v2")) { if (request.getPath().startsWith("/notifications/v2")) {
String notifications = request.getRequestUrl().queryParameter("notifications"); String notifications = request.getRequestUrl().queryParameter("notifications");
return new MockResponse().setResponseCode(200).setBody(mockLongPollBody(notifications)); return new MockResponse().setResponseCode(200).setBody(mockLongPollBody(notifications));
} else if (request.getPath().startsWith("/configs")) { }
if (request.getPath().startsWith("/configs")) {
List<String> pathSegments = request.getRequestUrl().pathSegments(); List<String> pathSegments = request.getRequestUrl().pathSegments();
// appId and cluster might be used in the future // appId and cluster might be used in the future
String appId = pathSegments.get(1); String appId = pathSegments.get(1);
......
...@@ -219,10 +219,9 @@ public class RetryableRestTemplate { ...@@ -219,10 +219,9 @@ public class RetryableRestTemplate {
return nestedException instanceof SocketTimeoutException return nestedException instanceof SocketTimeoutException
|| nestedException instanceof HttpHostConnectException || nestedException instanceof HttpHostConnectException
|| nestedException instanceof ConnectTimeoutException; || nestedException instanceof ConnectTimeoutException;
} else {
return nestedException instanceof HttpHostConnectException
|| nestedException instanceof ConnectTimeoutException;
} }
return nestedException instanceof HttpHostConnectException
|| nestedException instanceof ConnectTimeoutException;
} }
} }
...@@ -56,23 +56,22 @@ public class GrayPublishEmailBuilder extends ConfigPublishEmailBuilder { ...@@ -56,23 +56,22 @@ public class GrayPublishEmailBuilder extends ConfigPublishEmailBuilder {
if (CollectionUtils.isEmpty(ruleItems)) { if (CollectionUtils.isEmpty(ruleItems)) {
return bodyTemplate.replaceAll(EMAIL_CONTENT_GRAY_RULES_MODULE, "<br><h4>无灰度规则</h4>"); return bodyTemplate.replaceAll(EMAIL_CONTENT_GRAY_RULES_MODULE, "<br><h4>无灰度规则</h4>");
} else {
StringBuilder rulesHtmlBuilder = new StringBuilder();
for (GrayReleaseRuleItemDTO ruleItem : ruleItems) {
String clientAppId = ruleItem.getClientAppId();
Set<String> ips = ruleItem.getClientIpList();
rulesHtmlBuilder.append("<b>AppId:&nbsp;</b>")
.append(clientAppId)
.append("&nbsp;&nbsp; <b>IP:&nbsp;</b>");
IP_JOINER.appendTo(rulesHtmlBuilder, ips);
}
String grayRulesModuleContent = portalConfig.emailGrayRulesModuleTemplate().replaceAll(EMAIL_CONTENT_GRAY_RULES_CONTENT,
Matcher.quoteReplacement(rulesHtmlBuilder.toString()));
return bodyTemplate.replaceAll(EMAIL_CONTENT_GRAY_RULES_MODULE, Matcher.quoteReplacement(grayRulesModuleContent));
} }
StringBuilder rulesHtmlBuilder = new StringBuilder();
for (GrayReleaseRuleItemDTO ruleItem : ruleItems) {
String clientAppId = ruleItem.getClientAppId();
Set<String> ips = ruleItem.getClientIpList();
rulesHtmlBuilder.append("<b>AppId:&nbsp;</b>")
.append(clientAppId)
.append("&nbsp;&nbsp; <b>IP:&nbsp;</b>");
IP_JOINER.appendTo(rulesHtmlBuilder, ips);
}
String grayRulesModuleContent = portalConfig.emailGrayRulesModuleTemplate().replaceAll(EMAIL_CONTENT_GRAY_RULES_CONTENT,
Matcher.quoteReplacement(rulesHtmlBuilder.toString()));
return bodyTemplate.replaceAll(EMAIL_CONTENT_GRAY_RULES_MODULE, Matcher.quoteReplacement(grayRulesModuleContent));
} }
} }
...@@ -75,9 +75,8 @@ public class AppController { ...@@ -75,9 +75,8 @@ public class AppController {
public List<App> findApps(@RequestParam(value = "appIds", required = false) String appIds) { public List<App> findApps(@RequestParam(value = "appIds", required = false) String appIds) {
if (StringUtils.isEmpty(appIds)) { if (StringUtils.isEmpty(appIds)) {
return appService.findAll(); return appService.findAll();
} else {
return appService.findByAppIds(Sets.newHashSet(appIds.split(",")));
} }
return appService.findByAppIds(Sets.newHashSet(appIds.split(",")));
} }
@GetMapping("/search/by-appid-or-name") @GetMapping("/search/by-appid-or-name")
...@@ -85,9 +84,8 @@ public class AppController { ...@@ -85,9 +84,8 @@ public class AppController {
Pageable pageable) { Pageable pageable) {
if (StringUtils.isEmpty(query)) { if (StringUtils.isEmpty(query)) {
return appService.findAll(pageable); return appService.findAll(pageable);
} else {
return appService.searchByAppIdOrAppName(query, pageable);
} }
return appService.searchByAppIdOrAppName(query, pageable);
} }
@GetMapping("/by-owner") @GetMapping("/by-owner")
......
...@@ -86,33 +86,32 @@ public class ConsumerController { ...@@ -86,33 +86,32 @@ public class ConsumerController {
} }
if (Objects.equals("AppRole", type)) { if (Objects.equals("AppRole", type)) {
return Collections.singletonList(consumerService.assignAppRoleToConsumer(token, appId)); return Collections.singletonList(consumerService.assignAppRoleToConsumer(token, appId));
} else { }
if (StringUtils.isEmpty(namespaceName)) { if (StringUtils.isEmpty(namespaceName)) {
throw new BadRequestException("Params(NamespaceName) can not be empty."); throw new BadRequestException("Params(NamespaceName) can not be empty.");
} }
if (null != envs){ if (null != envs){
String[] envArray = envs.split(","); String[] envArray = envs.split(",");
List<String> envList = Lists.newArrayList(); List<String> envList = Lists.newArrayList();
// validate env parameter // validate env parameter
for (String env : envArray) { for (String env : envArray) {
if (Strings.isNullOrEmpty(env)) { if (Strings.isNullOrEmpty(env)) {
continue; continue;
}
if (Env.UNKNOWN == EnvUtils.transformEnv(env)) {
throw new BadRequestException(String.format("env: %s is illegal", env));
}
envList.add(env);
} }
if (Env.UNKNOWN == EnvUtils.transformEnv(env)) {
List<ConsumerRole> consumeRoles = new ArrayList<>(); throw new BadRequestException(String.format("env: %s is illegal", env));
for (String env : envList) {
consumeRoles.addAll(consumerService.assignNamespaceRoleToConsumer(token, appId, namespaceName, env));
} }
return consumeRoles; envList.add(env);
} }
return consumerService.assignNamespaceRoleToConsumer(token, appId, namespaceName); List<ConsumerRole> consumeRoles = new ArrayList<>();
for (String env : envList) {
consumeRoles.addAll(consumerService.assignNamespaceRoleToConsumer(token, appId, namespaceName, env));
}
return consumeRoles;
} }
return consumerService.assignNamespaceRoleToConsumer(token, appId, namespaceName);
} }
......
...@@ -194,8 +194,7 @@ public class ItemController { ...@@ -194,8 +194,7 @@ public class ItemController {
configService.syncItems(model.getSyncToNamespaces(), model.getSyncItems()); configService.syncItems(model.getSyncToNamespaces(), model.getSyncItems());
return ResponseEntity.status(HttpStatus.OK).build(); return ResponseEntity.status(HttpStatus.OK).build();
} }
else throw new AccessDeniedException(String.format("You don't have the permission to modify environment: %s", envNoPermission));
throw new AccessDeniedException(String.format("You don't have the permission to modify environment: %s", envNoPermission));
} }
@PreAuthorize(value = "@permissionValidator.hasModifyNamespacePermission(#appId, #namespaceName, #env)") @PreAuthorize(value = "@permissionValidator.hasModifyNamespacePermission(#appId, #namespaceName, #env)")
......
...@@ -40,11 +40,11 @@ public class ServerConfigController { ...@@ -40,11 +40,11 @@ public class ServerConfigController {
serverConfig.setDataChangeLastModifiedBy(modifiedBy); serverConfig.setDataChangeLastModifiedBy(modifiedBy);
serverConfig.setId(0L);//为空,设置ID 为0,jpa执行新增操作 serverConfig.setId(0L);//为空,设置ID 为0,jpa执行新增操作
return serverConfigRepository.save(serverConfig); return serverConfigRepository.save(serverConfig);
} else {//update
BeanUtils.copyEntityProperties(serverConfig, storedConfig);
storedConfig.setDataChangeLastModifiedBy(modifiedBy);
return serverConfigRepository.save(storedConfig);
} }
//update
BeanUtils.copyEntityProperties(serverConfig, storedConfig);
storedConfig.setDataChangeLastModifiedBy(modifiedBy);
return serverConfigRepository.save(storedConfig);
} }
@PreAuthorize(value = "@permissionValidator.isSuperAdmin()") @PreAuthorize(value = "@permissionValidator.isSuperAdmin()")
......
...@@ -48,9 +48,8 @@ public class UserInfo { ...@@ -48,9 +48,8 @@ public class UserInfo {
UserInfo anotherUser = (UserInfo) o; UserInfo anotherUser = (UserInfo) o;
return userId.equals(anotherUser.userId); return userId.equals(anotherUser.userId);
} else {
return false;
} }
return false;
} }
} }
...@@ -101,9 +101,8 @@ public class ConfigPublishListener { ...@@ -101,9 +101,8 @@ public class ConfigPublishListener {
if (publishInfo.isRollbackEvent()) { if (publishInfo.isRollbackEvent()) {
return releaseHistoryService return releaseHistoryService
.findLatestByPreviousReleaseIdAndOperation(env, publishInfo.getPreviousReleaseId(), operation); .findLatestByPreviousReleaseIdAndOperation(env, publishInfo.getPreviousReleaseId(), operation);
} else {
return releaseHistoryService.findLatestByReleaseIdAndOperation(env, publishInfo.getReleaseId(), operation);
} }
return releaseHistoryService.findLatestByReleaseIdAndOperation(env, publishInfo.getReleaseId(), operation);
} }
......
...@@ -239,10 +239,10 @@ public class ItemService { ...@@ -239,10 +239,10 @@ public class ItemService {
if (sourceComment == null) { if (sourceComment == null) {
return !StringUtils.isEmpty(targetComment); return !StringUtils.isEmpty(targetComment);
} else if (targetComment != null) { }
if (targetComment != null) {
return !sourceComment.equals(targetComment); return !sourceComment.equals(targetComment);
} else {
return false;
} }
return false;
} }
} }
...@@ -126,9 +126,8 @@ public class ReleaseService { ...@@ -126,9 +126,8 @@ public class ReleaseService {
List<ReleaseDTO> releases = findReleaseByIds(env, releaseIds); List<ReleaseDTO> releases = findReleaseByIds(env, releaseIds);
if (CollectionUtils.isEmpty(releases)) { if (CollectionUtils.isEmpty(releases)) {
return null; return null;
} else {
return releases.get(0);
} }
return releases.get(0);
} }
......
...@@ -373,15 +373,15 @@ public class AuthConfiguration { ...@@ -373,15 +373,15 @@ public class AuthConfiguration {
ldapProperties.getSearchFilter(), ldapContextSource); ldapProperties.getSearchFilter(), ldapContextSource);
filterBasedLdapUserSearch.setSearchSubtree(true); filterBasedLdapUserSearch.setSearchSubtree(true);
return filterBasedLdapUserSearch; return filterBasedLdapUserSearch;
} else {
FilterLdapByGroupUserSearch filterLdapByGroupUserSearch = new FilterLdapByGroupUserSearch(
ldapProperties.getBase(), ldapProperties.getSearchFilter(), ldapExtendProperties.getGroup().getGroupBase(),
ldapContextSource, ldapExtendProperties.getGroup().getGroupSearch(),
ldapExtendProperties.getMapping().getRdnKey(),
ldapExtendProperties.getGroup().getGroupMembership(),ldapExtendProperties.getMapping().getLoginId());
filterLdapByGroupUserSearch.setSearchSubtree(true);
return filterLdapByGroupUserSearch;
} }
FilterLdapByGroupUserSearch filterLdapByGroupUserSearch = new FilterLdapByGroupUserSearch(
ldapProperties.getBase(), ldapProperties.getSearchFilter(), ldapExtendProperties.getGroup().getGroupBase(),
ldapContextSource, ldapExtendProperties.getGroup().getGroupSearch(),
ldapExtendProperties.getMapping().getRdnKey(),
ldapExtendProperties.getGroup().getGroupMembership(),ldapExtendProperties.getMapping().getLoginId());
filterLdapByGroupUserSearch.setSearchSubtree(true);
return filterLdapByGroupUserSearch;
} }
@Bean @Bean
......
...@@ -67,16 +67,16 @@ public class ApolloLdapAuthenticationProvider extends LdapAuthenticationProvider ...@@ -67,16 +67,16 @@ public class ApolloLdapAuthenticationProvider extends LdapAuthenticationProvider
if (!StringUtils.hasLength(username)) { if (!StringUtils.hasLength(username)) {
throw new BadCredentialsException( throw new BadCredentialsException(
this.messages.getMessage("LdapAuthenticationProvider.emptyUsername", "Empty Username")); this.messages.getMessage("LdapAuthenticationProvider.emptyUsername", "Empty Username"));
} else if (!StringUtils.hasLength(password)) { }
if (!StringUtils.hasLength(password)) {
throw new BadCredentialsException(this.messages throw new BadCredentialsException(this.messages
.getMessage("AbstractLdapAuthenticationProvider.emptyPassword", "Empty Password")); .getMessage("AbstractLdapAuthenticationProvider.emptyPassword", "Empty Password"));
} else {
Assert.notNull(password, "Null password was supplied in authentication token");
DirContextOperations userData = this.doAuthentication(userToken);
String loginId = userData.getStringAttribute(properties.getMapping().getLoginId());
UserDetails user = this.userDetailsContextMapper.mapUserFromContext(userData, loginId,
this.loadUserAuthorities(userData, loginId, (String) authentication.getCredentials()));
return this.createSuccessfulAuthentication(userToken, user);
} }
Assert.notNull(password, "Null password was supplied in authentication token");
DirContextOperations userData = this.doAuthentication(userToken);
String loginId = userData.getStringAttribute(properties.getMapping().getLoginId());
UserDetails user = this.userDetailsContextMapper.mapUserFromContext(userData, loginId,
this.loadUserAuthorities(userData, loginId, (String) authentication.getCredentials()));
return this.createSuccessfulAuthentication(userToken, user);
} }
} }
...@@ -81,17 +81,16 @@ public class FilterLdapByGroupUserSearch extends FilterBasedLdapUserSearch { ...@@ -81,17 +81,16 @@ public class FilterLdapByGroupUserSearch extends FilterBasedLdapUserSearch {
} }
} }
throw new UsernameNotFoundException("User " + username + " not found in directory."); throw new UsernameNotFoundException("User " + username + " not found in directory.");
} else { }
String[] memberUids = ((DirContextAdapter) ctx) String[] memberUids = ((DirContextAdapter) ctx)
.getStringAttributes(groupMembershipAttrName); .getStringAttributes(groupMembershipAttrName);
for (String memberUid : memberUids) { for (String memberUid : memberUids) {
if (memberUid.equalsIgnoreCase(username)) { if (memberUid.equalsIgnoreCase(username)) {
Name name = searchUserById(memberUid); Name name = searchUserById(memberUid);
LdapName ldapName = LdapUtils.newLdapName(name); LdapName ldapName = LdapUtils.newLdapName(name);
LdapName ldapRdn = LdapUtils LdapName ldapRdn = LdapUtils
.removeFirst(ldapName, LdapUtils.newLdapName(searchBase)); .removeFirst(ldapName, LdapUtils.newLdapName(searchBase));
return new DirContextAdapter(ldapRdn); return new DirContextAdapter(ldapRdn);
}
} }
} }
throw new UsernameNotFoundException("User " + username + " not found in directory."); throw new UsernameNotFoundException("User " + username + " not found in directory.");
......
...@@ -167,12 +167,10 @@ public class LdapUserService implements UserService { ...@@ -167,12 +167,10 @@ public class LdapUserService implements UserService {
if (userIds != null) { if (userIds != null) {
if (userIds.stream().anyMatch(c -> c.equals(tmp.getUserId()))) { if (userIds.stream().anyMatch(c -> c.equals(tmp.getUserId()))) {
return tmp; return tmp;
} else {
return null;
} }
} else { return null;
return tmp;
} }
return tmp;
}); });
} }
...@@ -224,24 +222,23 @@ public class LdapUserService implements UserService { ...@@ -224,24 +222,23 @@ public class LdapUserService implements UserService {
} }
return userInfos; return userInfos;
} else { }
List<UserInfo> userInfos = new ArrayList<>(); List<UserInfo> userInfos = new ArrayList<>();
String[] memberUids = ((DirContextAdapter) ctx) String[] memberUids = ((DirContextAdapter) ctx)
.getStringAttributes(groupMembershipAttrName); .getStringAttributes(groupMembershipAttrName);
for (String memberUid : memberUids) { for (String memberUid : memberUids) {
UserInfo userInfo = searchUserById(memberUid); UserInfo userInfo = searchUserById(memberUid);
if (userInfo != null) { if (userInfo != null) {
if (keyword != null) { if (keyword != null) {
if (userInfo.getUserId().toLowerCase().contains(keyword.toLowerCase())) { if (userInfo.getUserId().toLowerCase().contains(keyword.toLowerCase())) {
userInfos.add(userInfo);
}
} else {
userInfos.add(userInfo); userInfos.add(userInfo);
} }
} else {
userInfos.add(userInfo);
} }
} }
return userInfos;
} }
return userInfos;
}); });
} }
...@@ -258,15 +255,14 @@ public class LdapUserService implements UserService { ...@@ -258,15 +255,14 @@ public class LdapUserService implements UserService {
} }
return -1; return -1;
})), ArrayList::new)); })), ArrayList::new));
} else {
ContainerCriteria criteria = ldapQueryCriteria();
if (!Strings.isNullOrEmpty(keyword)) {
criteria.and(query().where(loginIdAttrName).like(keyword + "*").or(userDisplayNameAttrName)
.like(keyword + "*"));
}
users = ldapTemplate.search(criteria, ldapUserInfoMapper);
return users;
} }
ContainerCriteria criteria = ldapQueryCriteria();
if (!Strings.isNullOrEmpty(keyword)) {
criteria.and(query().where(loginIdAttrName).like(keyword + "*").or(userDisplayNameAttrName)
.like(keyword + "*"));
}
users = ldapTemplate.search(criteria, ldapUserInfoMapper);
return users;
} }
@Override @Override
...@@ -278,30 +274,27 @@ public class LdapUserService implements UserService { ...@@ -278,30 +274,27 @@ public class LdapUserService implements UserService {
return lists.get(0); return lists.get(0);
} }
return null; return null;
} else {
return ldapTemplate
.searchForObject(ldapQueryCriteria().and(loginIdAttrName).is(userId), ldapUserInfoMapper);
} }
return ldapTemplate
.searchForObject(ldapQueryCriteria().and(loginIdAttrName).is(userId), ldapUserInfoMapper);
} }
@Override @Override
public List<UserInfo> findByUserIds(List<String> userIds) { public List<UserInfo> findByUserIds(List<String> userIds) {
if (CollectionUtils.isEmpty(userIds)) { if (CollectionUtils.isEmpty(userIds)) {
return Collections.emptyList(); return Collections.emptyList();
} else {
List<UserInfo> userList = new ArrayList<>();
if (StringUtils.isNotBlank(groupSearch)) {
List<UserInfo> userListByGroup = searchUserInfoByGroup(groupBase, groupSearch, null,
userIds);
userList.addAll(userListByGroup);
return userList;
} else {
ContainerCriteria criteria = query().where(loginIdAttrName).is(userIds.get(0));
userIds.stream().skip(1).forEach(userId -> criteria.or(loginIdAttrName).is(userId));
return ldapTemplate.search(ldapQueryCriteria().and(criteria), ldapUserInfoMapper);
}
} }
List<UserInfo> userList = new ArrayList<>();
if (StringUtils.isNotBlank(groupSearch)) {
List<UserInfo> userListByGroup = searchUserInfoByGroup(groupBase, groupSearch, null,
userIds);
userList.addAll(userListByGroup);
return userList;
}
ContainerCriteria criteria = query().where(loginIdAttrName).is(userIds.get(0));
userIds.stream().skip(1).forEach(userId -> criteria.or(loginIdAttrName).is(userId));
return ldapTemplate.search(ldapQueryCriteria().and(criteria), ldapUserInfoMapper);
} }
} }
...@@ -53,9 +53,8 @@ public class RelativeDateFormat { ...@@ -53,9 +53,8 @@ public class RelativeDateFormat {
long months = toMonths(delta); long months = toMonths(delta);
if (months <= 3) { if (months <= 3) {
return (months <= 0 ? 1 : months) + ONE_MONTH_AGO; return (months <= 0 ? 1 : months) + ONE_MONTH_AGO;
} else {
return TIMESTAMP_FORMAT.format(date);
} }
return TIMESTAMP_FORMAT.format(date);
} }
private static long toSeconds(long date) { private static long toSeconds(long date) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment