Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
apollo
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
apollo
Commits
5ca5a63f
Commit
5ca5a63f
authored
Jan 31, 2019
by
kezhenxu94
Committed by
Jason Song
Jan 31, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
polishing code with lambdas or method reference (#1929)
parent
7e4ba422
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
43 additions
and
57 deletions
+43
-57
apollo-configservice/src/main/java/com/ctrip/framework/apollo/configservice/controller/ConfigFileController.java
...apollo/configservice/controller/ConfigFileController.java
+13
-21
apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/service/ConsumerRolePermissionService.java
...apollo/openapi/service/ConsumerRolePermissionService.java
+1
-2
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/api/AdminServiceAPI.java
...om/ctrip/framework/apollo/portal/api/AdminServiceAPI.java
+1
-3
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ctrip/WebContextConfiguration.java
...work/apollo/portal/spi/ctrip/WebContextConfiguration.java
+11
-16
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultRoleInitializationService.java
...tal/spi/defaultimpl/DefaultRoleInitializationService.java
+10
-9
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultRolePermissionService.java
.../portal/spi/defaultimpl/DefaultRolePermissionService.java
+6
-5
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/ConfigToFileUtils.java
...ctrip/framework/apollo/portal/util/ConfigToFileUtils.java
+1
-1
No files found.
apollo-configservice/src/main/java/com/ctrip/framework/apollo/configservice/controller/ConfigFileController.java
View file @
5ca5a63f
...
...
@@ -77,16 +77,9 @@ public class ConfigFileController implements ReleaseMessageListener {
final
GrayReleaseRulesHolder
grayReleaseRulesHolder
)
{
localCache
=
CacheBuilder
.
newBuilder
()
.
expireAfterWrite
(
EXPIRE_AFTER_WRITE
,
TimeUnit
.
MINUTES
)
.
weigher
(
new
Weigher
<
String
,
String
>()
{
@Override
public
int
weigh
(
String
key
,
String
value
)
{
return
value
==
null
?
0
:
value
.
length
();
}
})
.
weigher
((
Weigher
<
String
,
String
>)
(
key
,
value
)
->
value
==
null
?
0
:
value
.
length
())
.
maximumWeight
(
MAX_CACHE_SIZE
)
.
removalListener
(
new
RemovalListener
<
String
,
String
>()
{
@Override
public
void
onRemoval
(
RemovalNotification
<
String
,
String
>
notification
)
{
.
removalListener
(
notification
->
{
String
cacheKey
=
notification
.
getKey
();
logger
.
debug
(
"removing cache key: {}"
,
cacheKey
);
if
(!
cacheKey2WatchedKeys
.
containsKey
(
cacheKey
))
{
...
...
@@ -99,7 +92,6 @@ public class ConfigFileController implements ReleaseMessageListener {
}
cacheKey2WatchedKeys
.
removeAll
(
cacheKey
);
logger
.
debug
(
"removed cache key: {}"
,
cacheKey
);
}
})
.
build
();
propertiesResponseHeaders
=
new
HttpHeaders
();
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/service/ConsumerRolePermissionService.java
View file @
5ca5a63f
...
...
@@ -47,8 +47,7 @@ public class ConsumerRolePermissionService {
}
Set
<
Long
>
roleIds
=
FluentIterable
.
from
(
consumerRoles
).
transform
(
consumerRole
->
consumerRole
.
getRoleId
())
.
toSet
();
FluentIterable
.
from
(
consumerRoles
).
transform
(
ConsumerRole:
:
getRoleId
).
toSet
();
List
<
RolePermission
>
rolePermissions
=
rolePermissionRepository
.
findByRoleIdIn
(
roleIds
);
if
(
CollectionUtils
.
isEmpty
(
rolePermissions
))
{
return
false
;
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/api/AdminServiceAPI.java
View file @
5ca5a63f
...
...
@@ -295,9 +295,7 @@ public class AdminServiceAPI {
parameters
.
add
(
"comment"
,
releaseComment
);
parameters
.
add
(
"operator"
,
operator
);
parameters
.
add
(
"isEmergencyPublish"
,
String
.
valueOf
(
isEmergencyPublish
));
grayDelKeys
.
forEach
(
key
->{
parameters
.
add
(
"grayDelKeys"
,
key
);
});
grayDelKeys
.
forEach
(
key
->
parameters
.
add
(
"grayDelKeys"
,
key
));
HttpEntity
<
MultiValueMap
<
String
,
String
>>
entity
=
new
HttpEntity
<>(
parameters
,
headers
);
ReleaseDTO
response
=
restTemplate
.
post
(
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ctrip/WebContextConfiguration.java
View file @
5ca5a63f
...
...
@@ -27,11 +27,7 @@ public class WebContextConfiguration {
@Bean
public
ServletContextInitializer
servletContextInitializer
()
{
return
new
ServletContextInitializer
()
{
@Override
public
void
onStartup
(
ServletContext
servletContext
)
throws
ServletException
{
return
servletContext
->
{
String
loggingServerIP
=
portalConfig
.
cloggingUrl
();
String
loggingServerPort
=
portalConfig
.
cloggingPort
();
String
credisServiceUrl
=
portalConfig
.
credisServiceUrl
();
...
...
@@ -42,7 +38,6 @@ public class WebContextConfiguration {
Strings
.
isNullOrEmpty
(
loggingServerPort
)
?
""
:
loggingServerPort
);
servletContext
.
setInitParameter
(
"credisServiceUrl"
,
Strings
.
isNullOrEmpty
(
credisServiceUrl
)
?
""
:
credisServiceUrl
);
}
};
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultRoleInitializationService.java
View file @
5ca5a63f
package
com
.
ctrip
.
framework
.
apollo
.
portal
.
spi
.
defaultimpl
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.portal.component.config.PortalConfig
;
import
com.google.common.collect.FluentIterable
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Sets
;
import
com.ctrip.framework.apollo.common.entity.App
;
import
com.ctrip.framework.apollo.common.entity.BaseEntity
;
import
com.ctrip.framework.apollo.core.ConfigConsts
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.portal.component.config.PortalConfig
;
import
com.ctrip.framework.apollo.portal.constant.PermissionType
;
import
com.ctrip.framework.apollo.portal.constant.RoleType
;
import
com.ctrip.framework.apollo.portal.entity.po.Permission
;
...
...
@@ -16,11 +13,15 @@ import com.ctrip.framework.apollo.portal.service.RoleInitializationService;
import
com.ctrip.framework.apollo.portal.service.RolePermissionService
;
import
com.ctrip.framework.apollo.portal.spi.UserInfoHolder
;
import
com.ctrip.framework.apollo.portal.util.RoleUtils
;
import
com.google.common.collect.FluentIterable
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Sets
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.*
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
/**
* Created by timothy on 2017/4/26.
...
...
@@ -114,7 +115,7 @@ public class DefaultRoleInitializationService implements RoleInitializationServi
Set
<
Permission
>
createdAppPermissions
=
rolePermissionService
.
createPermissions
(
appPermissions
);
Set
<
Long
>
appPermissionIds
=
FluentIterable
.
from
(
createdAppPermissions
).
transform
(
permission
->
permission
.
getId
()).
toSet
(
);
createdAppPermissions
.
stream
().
map
(
BaseEntity:
:
getId
).
collect
(
Collectors
.
toSet
()
);
//create app master role
Role
appMasterRole
=
createRole
(
RoleUtils
.
buildAppMasterRoleName
(
appId
),
operator
);
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultRolePermissionService.java
View file @
5ca5a63f
...
...
@@ -18,15 +18,16 @@ import com.google.common.collect.HashMultimap;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Multimap
;
import
com.google.common.collect.Sets
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.CollectionUtils
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.CollectionUtils
;
/**
* Created by timothy on 2017/4/26.
...
...
@@ -85,7 +86,7 @@ public class DefaultRolePermissionService implements RolePermissionService {
List
<
UserRole
>
existedUserRoles
=
userRoleRepository
.
findByUserIdInAndRoleId
(
userIds
,
role
.
getId
());
Set
<
String
>
existedUserIds
=
FluentIterable
.
from
(
existedUserRoles
).
transform
(
userRole
->
userRole
.
getUserId
()).
toSet
(
);
existedUserRoles
.
stream
().
map
(
UserRole:
:
getUserId
).
collect
(
Collectors
.
toSet
()
);
Set
<
String
>
toAssignUserIds
=
Sets
.
difference
(
userIds
,
existedUserIds
);
...
...
@@ -170,7 +171,7 @@ public class DefaultRolePermissionService implements RolePermissionService {
}
Set
<
Long
>
roleIds
=
FluentIterable
.
from
(
userRoles
).
transform
(
userRole
->
userRole
.
getRoleId
()).
toSet
(
);
userRoles
.
stream
().
map
(
UserRole:
:
getRoleId
).
collect
(
Collectors
.
toSet
()
);
List
<
RolePermission
>
rolePermissions
=
rolePermissionRepository
.
findByRoleIdIn
(
roleIds
);
if
(
CollectionUtils
.
isEmpty
(
rolePermissions
))
{
return
false
;
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/ConfigToFileUtils.java
View file @
5ca5a63f
...
...
@@ -16,7 +16,7 @@ public class ConfigToFileUtils {
public
static
void
itemsToFile
(
OutputStream
os
,
List
<
String
>
items
)
{
try
{
PrintWriter
printWriter
=
new
PrintWriter
(
os
);
items
.
forEach
(
item
->
printWriter
.
println
(
item
)
);
items
.
forEach
(
printWriter:
:
println
);
printWriter
.
close
();
}
catch
(
Exception
e
)
{
throw
e
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment